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: 添加更多路由
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +108,8 @@ func (app *Application) Start() error {
|
||||
app.logger.Info("API启动成功")
|
||||
|
||||
// 启动任务执行器组件
|
||||
app.logger.Info("启动任务执行器")
|
||||
app.TaskExecutor.Start()
|
||||
app.logger.Info("任务执行器启动成功")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -123,8 +123,8 @@ func (app *Application) Stop() error {
|
||||
}
|
||||
|
||||
// 停止任务执行器组件
|
||||
app.logger.Info("停止任务执行器")
|
||||
app.TaskExecutor.Stop()
|
||||
app.logger.Info("任务执行器已停止")
|
||||
|
||||
// 停止存储组件
|
||||
if err := app.Storage.Disconnect(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user