fix: resolve marketing static page path across working dirs
This commit is contained in:
@@ -2,6 +2,8 @@ package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
@@ -20,6 +22,29 @@ import (
|
||||
smokehandler "wx_service/internal/smoke/handler"
|
||||
)
|
||||
|
||||
func resolveMarketingPage() string {
|
||||
candidates := []string{
|
||||
filepath.Join("web", "marketing", "index.html"),
|
||||
filepath.Join("..", "web", "marketing", "index.html"),
|
||||
}
|
||||
|
||||
if executable, err := os.Executable(); err == nil {
|
||||
exeDir := filepath.Dir(executable)
|
||||
candidates = append(candidates,
|
||||
filepath.Join(exeDir, "web", "marketing", "index.html"),
|
||||
filepath.Join(exeDir, "..", "web", "marketing", "index.html"),
|
||||
)
|
||||
}
|
||||
|
||||
for _, path := range candidates {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Join("web", "marketing", "index.html")
|
||||
}
|
||||
|
||||
func Register(
|
||||
router *gin.Engine,
|
||||
db *gorm.DB,
|
||||
@@ -84,8 +109,9 @@ func Register(
|
||||
}
|
||||
|
||||
// Web 管理后台静态文件
|
||||
router.StaticFile("/admin/marketing", "web/marketing/index.html")
|
||||
router.StaticFile("/admin/marketing/", "web/marketing/index.html")
|
||||
marketingPage := resolveMarketingPage()
|
||||
router.StaticFile("/admin/marketing", marketingPage)
|
||||
router.StaticFile("/admin/marketing/", marketingPage)
|
||||
|
||||
// 健康检查:用于容器/负载均衡探活
|
||||
router.GET("/healthz", func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user