feat(server): 优化 Swagger 配置,支持动态 host

- 移除 swagger.json/yaml 中硬编码的 host 字段
- 在 docs.go 中将 Host 设置为空字符串以支持动态检测
- 添加前端 /swagger 代理配置,支持开发环境访问 Swagger UI
- 在 main.go 中导入 docs 包注册 Swagger 文档
This commit is contained in:
2026-07-15 13:30:59 +08:00
parent 8898437e9e
commit 1d799ac0e7
5 changed files with 6 additions and 4 deletions
+4
View File
@@ -27,6 +27,10 @@ export default defineConfig({
target: 'http://localhost:8080', target: 'http://localhost:8080',
changeOrigin: true, changeOrigin: true,
}, },
'/swagger': {
target: 'http://localhost:8080',
changeOrigin: true,
},
}, },
}, },
build: { build: {
+1 -1
View File
@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
_ "github.com/1024XEngineer/xinfra/server/docs"
"github.com/1024XEngineer/xinfra/server/internal/handler" "github.com/1024XEngineer/xinfra/server/internal/handler"
"github.com/1024XEngineer/xinfra/server/internal/middleware" "github.com/1024XEngineer/xinfra/server/internal/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -22,7 +23,6 @@ import (
// @license.name Apache 2.0 // @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /api/v1 // @BasePath /api/v1
// @securityDefinitions.apikey BearerAuth // @securityDefinitions.apikey BearerAuth
+1 -1
View File
@@ -350,7 +350,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "1.0", Version: "1.0",
Host: "localhost:8080", Host: "",
BasePath: "/api/v1", BasePath: "/api/v1",
Schemes: []string{}, Schemes: []string{},
Title: "xinfra API", Title: "xinfra API",
-1
View File
@@ -15,7 +15,6 @@
}, },
"version": "1.0" "version": "1.0"
}, },
"host": "localhost:8080",
"basePath": "/api/v1", "basePath": "/api/v1",
"paths": { "paths": {
"/ping": { "/ping": {
-1
View File
@@ -20,7 +20,6 @@ definitions:
description: 响应消息 description: 响应消息
type: string type: string
type: object type: object
host: localhost:8080
info: info:
contact: contact:
email: support@swagger.io email: support@swagger.io