feat: auto configure console queue

This commit is contained in:
2026-09-21 03:49:38 +08:00
parent 3c8a9ac47c
commit 45a2b361f2
7 changed files with 77 additions and 10 deletions

View File

@@ -2,8 +2,10 @@ package httpserver
import (
"embed"
"encoding/json"
"io/fs"
"net/http"
"os"
)
// consoleAssets 将控制台静态资源编译进 Orbit,避免运行容器依赖 Node.js、外部 CDN
@@ -30,6 +32,16 @@ func RegisterConsole(server *http.Server) {
mux.HandleFunc("GET /console", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/console/", http.StatusPermanentRedirect)
})
mux.HandleFunc("GET /console/config", func(w http.ResponseWriter, r *http.Request) {
// 队列 ID 只是控制台的默认范围,不是凭据。Token 仍由每个授权 API
// 自己校验;这里不返回任何秘密,也不访问数据库。
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Content-Type-Options", "nosniff")
_ = json.NewEncoder(w).Encode(struct {
DefaultQueueID string `json:"default_queue_id"`
}{DefaultQueueID: os.Getenv("ORBIT_CONSOLE_QUEUE_ID")})
})
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")