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