1. 增加前端测试界面
2. 修复重复输出日志的问题
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/api/middleware"
|
||||
@@ -203,6 +204,26 @@ func (a *API) setupRoutes() {
|
||||
}
|
||||
}
|
||||
|
||||
// 使用NoRoute处理器处理前端路由
|
||||
a.engine.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
|
||||
// 判断是否为API路径
|
||||
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/ws/") {
|
||||
// API路径返回404
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"error": "API路径未找到",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 其他路径提供前端静态文件服务
|
||||
c.File("./frontend/index.html")
|
||||
})
|
||||
|
||||
// 静态文件服务 - 提供前端静态资源
|
||||
a.engine.Static("/static", "./frontend/static")
|
||||
|
||||
// TODO: 添加更多路由
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user