fixed bugs
All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 30s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m3s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 45s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m30s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 45s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m27s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 51s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m41s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m5s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 46s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m28s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m4s

This commit is contained in:
2026-01-02 02:44:21 +08:00
parent f58cab4e56
commit 7475957195

View File

@@ -121,8 +121,17 @@ type spaHandler struct {
func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
// 尝试打开请求的文件
f, err := h.fs.Open(path)
if err != nil {
// 文件不存在时,检查是否是静态资源请求
// 静态资源js, css, 图片等)应该返回 404而不是 index.html
if isStaticAsset(path) {
http.Error(w, "Not Found", http.StatusNotFound)
return
}
// 其他路径返回 index.htmlSPA 路由)
f, err = h.fs.Open("index.html")
if err != nil {
http.Error(w, "Not Found", http.StatusNotFound)
@@ -151,6 +160,20 @@ func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
// isStaticAsset 检查路径是否是静态资源
func isStaticAsset(path string) bool {
staticExtensions := []string{
".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico",
".woff", ".woff2", ".ttf", ".eot", ".map", ".json",
}
for _, ext := range staticExtensions {
if len(path) > len(ext) && path[len(path)-len(ext):] == ext {
return true
}
}
return false
}
// Re-export types from handler package for backward compatibility
type (
ServerInterface = handler.ServerInterface