feat(server): embed SPA dist with fallback handler; single-binary deploy

This commit is contained in:
2026-04-29 10:43:42 +08:00
parent 04a19dbcef
commit 78989a42ac
8 changed files with 70 additions and 2 deletions
+7
View File
@@ -17,6 +17,9 @@ type RouterDeps struct {
HealthCheck func(*http.Request) error
// ReadyCheck is invoked from GET /readyz with the same contract.
ReadyCheck func(*http.Request) error
// SPAHandler 为 nil 时禁用前端 fallback;非 nil 时挂到 chi NotFound,
// 把未匹配的请求交给 SPA handler 处理(静态文件 + index.html 回退)。
SPAHandler http.Handler
}
// NewRouter builds the application's chi.Router with the standard
@@ -46,5 +49,9 @@ func NewRouter(deps RouterDeps) chi.Router {
_, _ = w.Write([]byte("ok"))
})
if deps.SPAHandler != nil {
r.NotFound(deps.SPAHandler.ServeHTTP)
}
return r
}