feat: add embedded Orbit console

This commit is contained in:
2026-09-21 01:05:38 +08:00
parent bf76f13430
commit 05ebc812df
10 changed files with 324 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
package httpserver
import (
"embed"
"io/fs"
"net/http"
)
// consoleAssets 将控制台静态资源编译进 Orbit,避免运行容器依赖 Node.js、外部 CDN
// 或额外的文件挂载。控制台只调用版本化 HTTP API,不读取数据库。
//
//go:embed console
var consoleAssets embed.FS
// RegisterConsole 注册本地及生产可复用的 Orbit 控制台入口。
// /console 不改变业务 API 的认证和路由;静态页面自身不包含凭据。
func RegisterConsole(server *http.Server) {
if server == nil {
return
}
mux, ok := server.Handler.(*http.ServeMux)
if !ok {
return
}
assets, err := fs.Sub(consoleAssets, "console")
if err != nil {
return
}
files := http.StripPrefix("/console/", http.FileServer(http.FS(assets)))
mux.HandleFunc("GET /console", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/console/", http.StatusPermanentRedirect)
})
mux.Handle("GET /console/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("X-Content-Type-Options", "nosniff")
files.ServeHTTP(w, r)
}))
}