From c701acdcd3557a37c00861297aecbe57afc3d511 Mon Sep 17 00:00:00 2001 From: xuewenG Date: Tue, 10 Dec 2024 22:55:29 +0800 Subject: [PATCH] fix: fix swagger pages not found --- backend/main.go | 6 ++++-- backend/main_prod.go | 16 ++++++++++++---- front/nuxt.config.ts | 6 +++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/backend/main.go b/backend/main.go index 65d08fa9..8be777bb 100644 --- a/backend/main.go +++ b/backend/main.go @@ -72,10 +72,12 @@ func main() { setupRouter(injector) migrateTo3(tx, myLogger) + e.HideBanner = true - myLogger.Info().Msgf("服务端启动成功,监听:%d端口...", cfg.Port) err = e.Start(fmt.Sprintf(":%d", cfg.Port)) - if err != nil { + if err == nil { + myLogger.Info().Msgf("服务端启动成功,监听:%d端口...", cfg.Port) + } else { myLogger.Fatal().Msgf("服务启动失败,错误原因:%s", err) } } diff --git a/backend/main_prod.go b/backend/main_prod.go index 622ddea5..749e976e 100644 --- a/backend/main_prod.go +++ b/backend/main_prod.go @@ -6,6 +6,7 @@ import ( "embed" "fmt" "net/http" + "strings" "github.com/ilyakaznacheev/cleanenv" _ "github.com/joho/godotenv/autoload" @@ -81,15 +82,22 @@ func main() { HTML5: true, Root: "public", // because files are located in `web` directory in `webAssets` fs Filesystem: http.FS(staticFiles), - })) + Skipper: func(c echo.Context) bool { + if strings.HasPrefix(c.Request().URL.Path, "/swagger/") { + return true + } - e.FileFS("/*", "public/index.html", staticFiles) + return false + }, + })) migrateTo3(tx, myLogger) + e.HideBanner = true - myLogger.Info().Msgf("服务端启动成功,监听:%d端口...", cfg.Port) err = e.Start(fmt.Sprintf(":%d", cfg.Port)) - if err != nil { + if err == nil { + myLogger.Info().Msgf("服务端启动成功,监听:%d端口...", cfg.Port) + } else { myLogger.Fatal().Msgf("服务启动失败,错误原因:%s", err) } } diff --git a/front/nuxt.config.ts b/front/nuxt.config.ts index bfaf04f1..2d2bf51d 100644 --- a/front/nuxt.config.ts +++ b/front/nuxt.config.ts @@ -49,7 +49,11 @@ export default defineNuxtConfig({ "/upload": { target: "http://localhost:37892", changeOrigin: true, - } + }, + "/swagger": { + target: "http://localhost:37892", + changeOrigin: true, + }, }, }, build: {