fix: register API routes before NoRoute to prevent route hijacking
Build and Deploy / build (push) Successful in 2m42s
Build and Deploy / deploy (push) Has been skipped

This commit is contained in:
2026-07-16 23:41:09 +00:00
parent ad6a130a6f
commit 1ff489971b
+7 -7
View File
@@ -48,13 +48,7 @@ func main() {
AllowCredentials: true, AllowCredentials: true,
})) }))
// 静态文件服务(前端 // API 路由(必须在 NoRoute 之前注册
r.Static("/assets", "./web/dist/assets")
r.NoRoute(func(c *gin.Context) {
c.File("./web/dist/index.html")
})
// API 路由
captchaHandler := handler.NewCaptchaHandler(captcha.NewHandler("./models")) captchaHandler := handler.NewCaptchaHandler(captcha.NewHandler("./models"))
captchaHandler.RegisterRoutes(r.Group(""), true) captchaHandler.RegisterRoutes(r.Group(""), true)
@@ -64,6 +58,12 @@ func main() {
c.JSON(200, gin.H{"installed": config.IsInstalled()}) c.JSON(200, gin.H{"installed": config.IsInstalled()})
}) })
// 静态文件服务(前端)- 必须在 API 路由之后
r.Static("/assets", "./web/dist/assets")
r.NoRoute(func(c *gin.Context) {
c.File("./web/dist/index.html")
})
// 健康检查 // 健康检查
r.GET("/health", func(c *gin.Context) { r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"}) c.JSON(200, gin.H{"status": "ok"})