chore: 官网拆分 homepage + 关于页瘦身 + 端口 5175(当前可用状态基线)

This commit is contained in:
Logan.Li committed 2026-10-14 20:31:51 +08:00
1 parent 5eb11826db
commit be151cb68f
85 files changed
+4420 -1530

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
package server
import (
"os"
"strings"
"net/http"
"path/filepath"
"runtime"
"github.com/gin-gonic/gin"
)
func NewRouter() *gin.Engine {
r := gin.New()
_ = r.SetTrustedProxies(nil)
r.Use(gin.Logger(), gin.Recovery())
r.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"ok": true, "service": "opsxshell-site"})
})
// 官网/文档已拆分独立静态站(homepage/dist,构建见 tools/homepage-build);本地仅静态托管预览。
for _, dir := range []string{
os.Getenv("OPSXSHELL_HOMEPAGE"),
"../../homepage/dist",
"../homepage/dist",
"homepage/dist",
} {
if dir == "" {
continue
}
if st, err := os.Stat(dir); err == nil && st.IsDir() {
fs := http.FileServer(http.Dir(dir))
r.NoRoute(func(c *gin.Context) {
p := c.Request.URL.Path
if strings.HasPrefix(p, "/api/") {
c.JSON(http.StatusNotFound, gin.H{"error": "接口不存在"})
return
}
upath := strings.TrimPrefix(p, "/")
if upath != "" {
if st2, err2 := os.Stat(filepath.Join(dir, upath)); err2 == nil && st2.IsDir() {
c.Request.URL.Path = p + "/"
} else if !strings.Contains(filepath.Base(upath), ".") {
if _, err3 := os.Stat(filepath.Join(dir, upath+".html")); err3 == nil {
c.Request.URL.Path = p + ".html"
}
}
}
fs.ServeHTTP(c.Writer, c.Request)
})
break
}
}
// 可选安装包目录(磁盘,不进 embed)
if dir := downloadDir(); dir != "" {
r.Static("/download", dir)
}
return r
}
func downloadDir() string {
_, file, _, ok := runtime.Caller(0)
if !ok {
return ""
}
// .../apps/server/internal/server/router.go → ../../download
dir := filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", "download"))
return dir
}