diff --git a/server/controllers/default.go b/server/controllers/default.go
index 155cb79..2f38933 100644
--- a/server/controllers/default.go
+++ b/server/controllers/default.go
@@ -8,6 +8,147 @@ type MainController struct {
beego.Controller
}
+// Get 处理根路径的 GET 请求,显示友好的欢迎页面
+func (c *MainController) Get() {
+ html := `
+
+
+
+
+ API 服务运行正常
+
+
+
+
+
+
API 服务运行正常
+
✓ 服务已成功启动并运行中
+
+
+
+
+
服务类型
+
RESTful API 服务
+
+
+
+
+
+`
+ c.Ctx.Output.Header("Content-Type", "text/html; charset=utf-8")
+ c.Ctx.Output.Body([]byte(html))
+}
+
// Hello 处理 /api/hello 请求
func (c *MainController) Hello() {
c.Data["json"] = map[string]string{"message": "Hello from Beego backend!"}
diff --git a/server/routers/router.go b/server/routers/router.go
index 28c3b4d..f76bd52 100644
--- a/server/routers/router.go
+++ b/server/routers/router.go
@@ -28,6 +28,157 @@ func init() {
}
})
+ // 处理浏览器访问 API 路径的情况 - 在路由之前拦截
+ beego.InsertFilter("/api/*", beego.BeforeRouter, func(ctx *context.Context) {
+ // 检查是否是浏览器访问(Accept 头包含 text/html)
+ accept := ctx.Input.Header("Accept")
+ if strings.Contains(accept, "text/html") {
+ html := `
+
+
+
+
+ API 服务运行正常
+
+
+
+
+
+
API 服务运行正常
+
✓ 服务已成功启动并运行中
+
+
+
+
+
访问路径
+
` + ctx.Input.URL() + `
+
+
+
请求方法
+
` + ctx.Input.Method() + `
+
+
+
+
+
+`
+ ctx.Output.Header("Content-Type", "text/html; charset=utf-8")
+ ctx.Output.Status = 200
+ ctx.Output.Body([]byte(html))
+ return
+ }
+ })
+
// 为除登录、登出和重置密码外的API路由应用JWT中间件
// 这样登录请求就不会被JWT中间件拦截
beego.InsertFilter("/api/*", beego.BeforeRouter, func(ctx *context.Context) {