diff --git a/gateway/main.go b/gateway/main.go index 7a0d5b2..1ce55c3 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -100,6 +100,17 @@ func main() { c.Redirect(http.StatusSeeOther, "/login") }) + // 新增通用静态文件路由(放在其他路由之后) + r.NoRoute(func(c *gin.Context) { + filePath := "./static" + c.Request.URL.Path + // 检查文件是否存在 + if _, err := os.Stat(filePath); err == nil { + http.ServeFile(c.Writer, c.Request, filePath) + } else { + c.AbortWithStatus(http.StatusNotFound) + } + }) + // 启动服务 r.Run(":7070") }