From c453d3425dbcb7734ec30a0b2aadc013dee9b93b Mon Sep 17 00:00:00 2001 From: cnbugs <717192502@qq.com> Date: Wed, 13 May 2026 11:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMIME=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9A=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= =?UTF-8?q?404=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=20+=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89base=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/main.go | 13 +++++++++++++ frontend/vite.config.ts | 1 + 2 files changed, 14 insertions(+) diff --git a/backend/main.go b/backend/main.go index 99043d1..828062c 100644 --- a/backend/main.go +++ b/backend/main.go @@ -5,7 +5,9 @@ import ( "auto-ssl/handlers" "auto-ssl/services" "log" + "net/http" "os" + "strings" "time" "github.com/gin-contrib/cors" @@ -57,6 +59,17 @@ func main() { } r.NoRoute(func(c *gin.Context) { + // 静态资源请求直接返回404,避免返回html导致MIME类型错误 + if strings.HasPrefix(c.Request.URL.Path, "/assets/") || + strings.HasSuffix(c.Request.URL.Path, ".js") || + strings.HasSuffix(c.Request.URL.Path, ".css") || + strings.HasSuffix(c.Request.URL.Path, ".png") || + strings.HasSuffix(c.Request.URL.Path, ".svg") || + strings.HasSuffix(c.Request.URL.Path, ".ico") { + c.AbortWithStatus(http.StatusNotFound) + return + } + // 其他路由返回index.html给前端处理 c.File("./dist/index.html") }) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index bbcf80c..d2b0bf5 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,4 +4,5 @@ import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], + base: process.env.VITE_BASE_URL || '/', })