build: 移除Dockerfile中的mailcap依赖并优化前端配置
Docker Build and Push / build (push) Has been cancelled

- 删除Dockerfile中不必要的mailcap包以精简镜像
- 将前端配置从process.env改为import.meta.env以适配现代构建工具
- 移除Go代码中手动设置mime类型的冗余逻辑
- 修复静态资源路由路径格式(/assets改为assets/)
- 优化导入语句格式和代码结构
This commit is contained in:
2026-02-10 20:46:06 +08:00
parent 7f9b638553
commit 07f4be3fc1
4 changed files with 14 additions and 18 deletions
+11 -10
View File
@@ -3,16 +3,17 @@ package routers
import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
"io"
"io/fs"
"message-nest/middleware"
"message-nest/pkg/setting"
"message-nest/routers/api"
"message-nest/routers/api/v1"
"message-nest/routers/api/v2"
v1 "message-nest/routers/api/v1"
v2 "message-nest/routers/api/v2"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// AppendCors 添加是否跨域(debug模式开启)
@@ -54,12 +55,12 @@ func AppendServerStaticHtmlWithPrefix(router gin.IRouter, f embed.FS, pathPrefix
}
htmlContent := string(content)
// 注入 base 标签和配置脚本
// base 标签必须在 head 的最前面,确保所有相对路径都基于这个 base
baseTag := fmt.Sprintf(`<base href="%s/">`, pathPrefix)
configScript := fmt.Sprintf(`<script>window.__URL_PATH_PREFIX__ = '%s';</script>`, pathPrefix)
// 在 <head> 标签后立即插入 base 标签
htmlContent = strings.Replace(htmlContent, "<head>", "<head>"+baseTag, 1)
// 在 </head> 标签前注入配置
@@ -73,7 +74,7 @@ func AppendServerStaticHtmlWithPrefix(router gin.IRouter, f embed.FS, pathPrefix
// 无路径前缀时,使用原有逻辑
if r, ok := router.(*gin.Engine); ok {
r.Use(middleware.StaticCacheMiddleware())
r.StaticFS("/assets", http.FS(assets))
r.StaticFS("assets/", http.FS(assets))
r.GET("/", func(ctx *gin.Context) {
ctx.FileFromFS("/", http.FS(dist))
})
@@ -93,13 +94,13 @@ func InitRouter(f embed.FS) *gin.Engine {
app.Use(gin.Recovery())
AppendCors(app)
// 获取 URL 前缀
pathPrefix := setting.ServerSetting.UrlPrefix
if pathPrefix != "" && pathPrefix[0] != '/' {
pathPrefix = "/" + pathPrefix
}
// 如果有路径前缀,创建路由组
var router gin.IRouter
if pathPrefix != "" {
@@ -107,7 +108,7 @@ func InitRouter(f embed.FS) *gin.Engine {
} else {
router = app
}
AppendServerStaticHtmlWithPrefix(router, f, pathPrefix)
router.POST("/auth", api.GetAuth)
@@ -171,7 +172,7 @@ func InitRouter(f embed.FS) *gin.Engine {
apiV1.POST("/templates/edit", v1.EditMessageTemplate)
apiV1.POST("/templates/delete", v1.DeleteMessageTemplate)
apiV1.POST("/templates/preview", v1.PreviewMessageTemplate)
// messageTemplate instances
apiV1.GET("/templates/ins/get", v1.GetTemplateWithIns)
apiV1.POST("/templates/ins/addone", v1.AddTemplateIns)