迁移 Flutter 端与训练脚本,模型/训练产物移出 git(遵循纯代码约定)

This commit is contained in:
2026-08-24 12:35:24 +08:00
parent d056f01965
commit 961523d94c
218 changed files with 13391 additions and 3232 deletions
+34
View File
@@ -0,0 +1,34 @@
package common
import (
"net/http"
"os"
"path/filepath"
"strings"
"github.com/gogf/gf/v2/net/ghttp"
)
// SpaFallback 单页应用 history 路由回退中间件:prefix 路径下请求对应的静态文件不存在
// (即前端路由,如 /admin/orders)时回退 index.html;真实静态文件交给后续静态服务处理。
// root 为前端构建产物目录,prefix 为托管路径前缀(如 "/admin")。
func SpaFallback(root, prefix string) ghttp.HandlerFunc {
root = filepath.Clean(root)
index := filepath.Join(root, "index.html")
return func(r *ghttp.Request) {
path := r.URL.Path
if r.Method == http.MethodGet && (path == prefix || strings.HasPrefix(path, prefix+"/")) {
rel := strings.TrimPrefix(path, prefix)
candidate := filepath.Clean(filepath.Join(root, rel))
if !strings.HasPrefix(candidate, root) {
r.Middleware.Next()
return
}
if _, err := os.Stat(candidate); err != nil {
r.Response.ServeFile(index)
return
}
}
r.Middleware.Next()
}
}