bike-festival-2024-backend (github.com)
DB Schema
User Table
Field | Type | GORM Options | JSON Key | Description |
---|---|---|---|---|
ID | string | type:varchar(36);primary_key | id | The unique identifier for the user. (from line account) |
Name | string | type:varchar(255);index | name | The name of the user. (from line account) |
User-Event Table
Field | Type | Description |
---|---|---|
user_id | varchar(36) | The ID of the user, linking to User.ID . |
event_id | varchar(36) | The ID of the event, linking to Event.ID . |
Event Table
Field | Type | GORM Options | JSON Key | Redis Key | Description |
---|---|---|---|---|---|
ID | *string | type:varchar(36);primary_key | id | id | The event ID defined at the frontend. If not provided, it is calculated by the hash of event detail and event time. |
EventTimeStart | *time.Time | type:timestamp | event_time_start | event_time_start | The start time of the event. |
EventTimeEnd | *time.Time | type:timestamp | event_time_end | event_time_end | The end time of the event. |
EventDetail | *string | type:varchar(1024) | event_detail | event_detail | The details of the event, stored in JSON format. This is parsed when sending to the line message API. |
心理測驗統計
- 結果種類儲存
- 統計趴數
Field | Type | GORM Options | Description |
---|---|---|---|
Type | string | type:varchar(255);unique | The unique type of the psycho test. |
Count | int | type:int | The count associated with the test. |
API
- Add type
- Retrieve statistic result
Line
Official Document
Tutorial
Line Login Integration Tutorial
Push Line Flex Message
- bike-festival-2024-backend/pkg/worker/event.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
- bike-festival-2024-backend/pkg/line_utils/flex.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
Asynq
- hibiken/asynq: Simple, reliable, and efficient distributed task queue in Go (github.com)
- hibiken/asynqmon: Web UI for Asynq task queue (github.com)
Add Scheduled Task
Cancel Scheduled Task
- asynq/inspector.go at master · hibiken/asynq (github.com)
- bike-festival-2024-backend/pkg/service/notify.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
Optimization
Get Event By EventID
DB only
(2000 virtual users, for 1 mins)
Redis Cache + DB
(2000 virtual users, for 1 mins)
1 | type EventCache struct { |
部署
Nginx Setup
Nginx Reverse Proxy
[!info]
要把
ssl_certificate & ssl_certificate_key
那邊的 domain 改成你自己的 (for Certbot)
1 | server { |
CertBot
1 | sudo apt install certbot |
Bug
Line login redirect
[!warning] the bug is due to the
referer-policy
the default policy isstrict-origin-when-cross-origin
In my case, I use the additional redirect_path(which is set in query string ``) to compose the frontend redirect path:
It works fine when I am developing at my local computer, but in the production environment, it always redirect user to the page with duplicate path, like:
/bikefest/main-stagebikefest/main-stage/
Then I discover that in my local development environment, the request referer only contain the domain name(
localhost:5173
), but the production send its full path and query string to the backend server.And that the reason is: in dev env, the frontend is at
localhost:5173
and the backend is atlocalhost:8000
, the trigger the default referer policystrict-origin-when-cross-origin
only send thelocalhost:8000
as the referer value. In prod env, the frontend and backend have the same domain but only differ at the path, so the refer default policy sendorigin
,path
,query
as the referer value, and frontend also send itswindows.location.path
asredirected_path
query string, then backend compose thereferer
,redirect_path
, and the result would be like `https:///windows.location.path/windows.location.path. And that is the main reason why the production appear the page with duplicate path. To resolve this problem, we only needs to set the referer policy in the nginx configuration, and let the referer only include
origin
to prevent the above issue:
1
2
3
4
5
6
7
8 server {
...
# Set the Referrer-Policy header
add_header Referrer-Policy "origin";
...
}