fix: register API routes before NoRoute to prevent route hijacking
This commit is contained in:
+7
-7
@@ -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"})
|
||||||
|
|||||||
Reference in New Issue
Block a user