diff --git a/api/auth/exchange.go b/api/auth/exchange.go index a128108..bc6df80 100644 --- a/api/auth/exchange.go +++ b/api/auth/exchange.go @@ -10,6 +10,7 @@ import ( ) // Exchange handles the authorization code swap process. +// // @Summary Exchange Auth Code // @Description Exchanges client credentials and user session for a specific redirect authorization code. // @Tags Authentication diff --git a/api/auth/magic.go b/api/auth/magic.go index 31469c9..35f7e72 100644 --- a/api/auth/magic.go +++ b/api/auth/magic.go @@ -9,6 +9,7 @@ import ( ) // Magic handles the "Magic Link" authentication request. +// // @Summary Request Magic Link // @Description Verifies Turnstile token and sends an authentication link via email. Returns the URI directly if debug mode is enabled. // @Tags Authentication diff --git a/api/auth/redirect.go b/api/auth/redirect.go index aa56dda..7e455ff 100644 --- a/api/auth/redirect.go +++ b/api/auth/redirect.go @@ -9,6 +9,7 @@ import ( ) // Redirect handles the post-verification callback and redirects the user to the target application. +// // @Summary Handle Auth Callback and Redirect // @Description Verifies the temporary email code, ensures the user exists (or creates one), validates the client's redirect URI, and finally performs a 302 redirect with a new authorization code. // @Tags Authentication diff --git a/api/auth/refresh.go b/api/auth/refresh.go index 8205108..a032c9b 100644 --- a/api/auth/refresh.go +++ b/api/auth/refresh.go @@ -9,6 +9,7 @@ import ( ) // Refresh handles the token rotation process. +// // @Summary Refresh Access Token // @Description Accepts a valid refresh token to issue a new access token and a rotated refresh token. // @Tags Authentication diff --git a/api/auth/token.go b/api/auth/token.go index c8257bb..e6294bd 100644 --- a/api/auth/token.go +++ b/api/auth/token.go @@ -9,6 +9,7 @@ import ( ) // Token exchanges an authorization code for access and refresh tokens. +// // @Summary Exchange Code for Token // @Description Verifies the provided authorization code and issues a pair of JWT tokens (Access and Refresh). // @Tags Authentication diff --git a/api/event/checkin.go b/api/event/checkin.go index 3c25084..e98ab6a 100644 --- a/api/event/checkin.go +++ b/api/event/checkin.go @@ -10,6 +10,7 @@ import ( ) // Checkin generates a check-in code for a specific event. +// // @Summary Generate Check-in Code // @Description Creates a temporary check-in code for the authenticated user and event. // @Tags Event @@ -49,6 +50,7 @@ func (self *EventHandler) Checkin(c *gin.Context) { } // CheckinSubmit validates a check-in code to complete attendance. +// // @Summary Submit Check-in Code // @Description Submits the generated code to mark the user as attended. // @Tags Event @@ -82,6 +84,7 @@ func (self *EventHandler) CheckinSubmit(c *gin.Context) { } // CheckinQuery retrieves the check-in status of a user for an event. +// // @Summary Query Check-in Status // @Description Returns the timestamp of when the user checked in, or null if not yet checked in. // @Tags Event diff --git a/api/event/info.go b/api/event/info.go index 232059c..6f63a6a 100644 --- a/api/event/info.go +++ b/api/event/info.go @@ -10,6 +10,7 @@ import ( ) // Info retrieves basic information about a specific event. +// // @Summary Get Event Information // @Description Fetches the name, start time, and end time of an event using its UUID. // @Tags Event diff --git a/api/user/full.go b/api/user/full.go index a94b6d7..b376836 100644 --- a/api/user/full.go +++ b/api/user/full.go @@ -9,6 +9,7 @@ import ( ) // Full retrieves the complete list of users directly from the database table. +// // @Summary Get Full User Table // @Description Fetches all user records without pagination. This is typically used for administrative overview or data export. // @Tags User diff --git a/api/user/info.go b/api/user/info.go index 70b42e0..b22faa8 100644 --- a/api/user/info.go +++ b/api/user/info.go @@ -10,6 +10,7 @@ import ( ) // Info retrieves the profile information of the currently authenticated user. +// // @Summary Get My User Information // @Description Fetches the complete profile data for the user associated with the provided session/token. // @Tags User diff --git a/api/user/list.go b/api/user/list.go index bc3dc7b..8baf8df 100644 --- a/api/user/list.go +++ b/api/user/list.go @@ -9,6 +9,7 @@ import ( ) // List retrieves a paginated list of users from the search engine. +// // @Summary List Users // @Description Fetches a list of users with support for pagination via limit and offset. Data is sourced from the search engine for high performance. // @Tags User diff --git a/api/user/update.go b/api/user/update.go index 68989f4..d6d3513 100644 --- a/api/user/update.go +++ b/api/user/update.go @@ -10,6 +10,7 @@ import ( ) // Update modifies the profile information for the currently authenticated user. +// // @Summary Update User Information // @Description Updates specific profile fields such as username, nickname, subtitle, avatar (URL), and bio (Base64). // @Description Validation: Username (5-255 chars), Nickname (max 24 chars), Subtitle (max 32 chars). diff --git a/container/client-cms.Containerfile b/container/client-cms.Containerfile index 0008d56..a49cfef 100644 --- a/container/client-cms.Containerfile +++ b/container/client-cms.Containerfile @@ -9,8 +9,8 @@ COPY . . RUN cd client/cms && pnpm install RUN cd client/cms && pnpm run build --outDir /app/.outputs/client/cms/dist -FROM docker.io/busybox:1.37 -WORKDIR /app -COPY --from=client-cms-build /app/.outputs/client/cms/dist . +FROM docker.io/caddy:2-alpine +COPY ./deploy/client-cms.Caddyfile /etc/caddy/Caddyfile +COPY --from=client-cms-build /app/.outputs/client/cms/dist /srv EXPOSE 3000 -ENTRYPOINT ["httpd", "-f", "-p", "3000", "-h", "/app", "-v"] +ENTRYPOINT ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] diff --git a/Caddyfile b/deploy/Caddyfile similarity index 69% rename from Caddyfile rename to deploy/Caddyfile index 3e7a53c..cd3eae6 100644 --- a/Caddyfile +++ b/deploy/Caddyfile @@ -1,9 +1,9 @@ test.nix.org.cn { - handle_path /* { - reverse_proxy client-cms:3000 - } - - handle_path /api/* { + handle /api/* { reverse_proxy backend:8000 } + + handle { + reverse_proxy client-cms:3000 + } } diff --git a/deploy/client-cms.Caddyfile b/deploy/client-cms.Caddyfile new file mode 100644 index 0000000..dfdd65a --- /dev/null +++ b/deploy/client-cms.Caddyfile @@ -0,0 +1,6 @@ +:3000 { + root * /srv + encode zstd gzip + try_files {path} /index.html + file_server +} diff --git a/conpose.yaml b/deploy/conpose.yaml similarity index 98% rename from conpose.yaml rename to deploy/conpose.yaml index e29e998..98f82bc 100644 --- a/conpose.yaml +++ b/deploy/conpose.yaml @@ -8,6 +8,8 @@ services: POSTGRES_DB: postgres volumes: - ./data/postgres:/var/lib/postgresql/data + ports: + - 5432:5432 healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"] interval: 5s diff --git a/go.mod b/go.mod index 3aa5302..e98cf52 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/spf13/viper v1.21.0 github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.1 + github.com/swaggo/swag v1.16.6 go.opentelemetry.io/contrib/bridges/otelslog v0.14.0 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.64.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 @@ -112,7 +113,6 @@ require ( github.com/spf13/cast v1.10.0 // indirect github.com/spf13/pflag v1.0.10 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/swaggo/swag v1.16.6 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.3.1 // indirect diff --git a/server/server.go b/server/server.go index 61a1285..70d649c 100644 --- a/server/server.go +++ b/server/server.go @@ -18,18 +18,18 @@ import ( _ "nixcn-cms/docs" ) -// @title NixCN CMS API -// @version 1.0 -// @description API Docs based on Gin framework -// @termsOfService http://swagger.io/terms/ -// @contact.name API Support -// @contact.url http://www.swagger.io/support -// @contact.email support@swagger.io -// @license.name Apache 2.0 -// @license.url http://www.apache.org/licenses/LICENSE-2.0.html -// @host localhost:8000 -// @BasePath /api/v1 -// @schemes http https +// @title NixCN CMS API +// @version 1.0 +// @description API Docs based on Gin framework +// @termsOfService http://swagger.io/terms/ +// @contact.name API Support +// @contact.url http://www.swagger.io/support +// @contact.email support@swagger.io +// @license.name Apache 2.0 +// @license.url http://www.apache.org/licenses/LICENSE-2.0.html +// @host localhost:8000 +// @BasePath /api/v1 +// @schemes http https func Start(ctx context.Context) { if !viper.GetBool("server.debug_mode") { gin.SetMode(gin.ReleaseMode)