fix(site): 按 Host 注入租户标题与 SEO 信息
This commit is contained in:
@@ -46,6 +46,7 @@ import (
|
||||
"hfb_sys/backend/internal/modules/user"
|
||||
"hfb_sys/backend/internal/modules/wallet"
|
||||
"hfb_sys/backend/internal/modules/withdrawal"
|
||||
"hfb_sys/backend/internal/storefrontshell"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
_ "hfb_sys/backend/docs" // Swagger 文档
|
||||
@@ -75,6 +76,16 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
tenantHandler := tenancy.NewHandler()
|
||||
jwtManager := auth.NewJWTManager(cfg.JWTSecret)
|
||||
|
||||
// 前台 HTML 外壳:Caddy 只把 HTML 文档请求转发到这里,由后端按 Host
|
||||
// 解析出的经营租户注入标题、图标和 SEO 信息。构建产物仍由 Caddy 托管,
|
||||
// 后端通过内网 shell 端点读取,避免复制 asset hash 不一致的 index.html。
|
||||
var storefrontShellHandler *storefrontshell.Handler
|
||||
if shellURL := strings.TrimSpace(cfg.FrontendShellURL); shellURL != "" {
|
||||
storefrontShellHandler = storefrontshell.NewHandler(storefrontshell.NewProvider(shellURL, logger), logger)
|
||||
} else if config.IsProductionEnv(cfg.AppEnv) && logger != nil {
|
||||
logger.Warn("FRONTEND_SHELL_URL 未配置,前台 HTML 不会按租户注入标题和图标")
|
||||
}
|
||||
|
||||
health := handler.NewHealthHandler(newReadinessChecks(deps))
|
||||
engine.GET("/health", health.Live)
|
||||
engine.GET("/health/ready", health.Ready)
|
||||
@@ -1060,5 +1071,15 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
}
|
||||
}
|
||||
|
||||
// SPA 兜底:只对 Caddy 转发来的 HTML 文档路径返回租户化外壳,
|
||||
// 其余未匹配路径保持原有 404 行为。
|
||||
engine.NoRoute(func(c *gin.Context) {
|
||||
if storefrontShellHandler != nil && storefrontshell.IsDocumentPath(c.Request.URL.Path) {
|
||||
storefrontShellHandler.Serve(c)
|
||||
return
|
||||
}
|
||||
c.String(http.StatusNotFound, "404 page not found")
|
||||
})
|
||||
|
||||
return engine
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user