Files
sundynix-agentix/sundynix-gateway/internal/webui/webui.go
T
Blizzard 28a1543249 feat(gateway): 内嵌 admin 控制台(go:embed),去掉单独 nginx 容器
复刻 sundynix-site 的 webfs 模式:gateway 一个容器同时 serve 控制台 UI + API + 供
桌面端直连。admin 用 HashRouter + API base 走相对 /api/v1(构建传 VITE_GATEWAY=''),
源码零改动即可同源 serve。

- internal/webui:go:embed all:admin_dist + Dist();占位 index.html 让不构建前端也能编译。
  目录命名 admin_dist(避开 .gitignore dist/ 与 .dockerignore **/dist 通配)。
- router.go NoRoute:非 /api/ 路径走内嵌静态,命中 /assets/* 直吐、否则回退 index.html;
  embed 失败仅 log 降级不影响 API。/metrics /healthz /readyz /api/v1 已注册,永不进 NoRoute。
- Dockerfile 加 admin node 构建 stage,go build 前 COPY dist 覆盖 embed 占位。
- live 验证:/ 返回 admin(200)、/assets/*.js(200)、/api/v1/admin/overview(401 走 API)、/healthz(200)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 14:45:24 +08:00

22 lines
804 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package webui 把 admin 运维控制台的前端构建产物打进 gateway 二进制。
// admin_dist/ 默认只有占位页;Docker 多阶段构建会先 `npm run build` 出真实产物、
// COPY 覆盖这里再编译 Go —— 于是一个 gateway 容器同时 serve 控制台 UI + API
// 无需单独的 admin nginx 容器(部署见 deploy/132-app)。
//
// 目录刻意命名 admin_dist 而非 dist:根 .gitignore(dist/) 与 .dockerignore(**/dist)
// 会忽略/排除 dist 目录,占位文件将无法提交、也进不了构建上下文。
package webui
import (
"embed"
"io/fs"
)
//go:embed all:admin_dist
var embeddedAdmin embed.FS
// Dist 返回 admin 控制台静态文件系统(挂在根 /)。
func Dist() (fs.FS, error) {
return fs.Sub(embeddedAdmin, "admin_dist")
}