优化数据库初始化逻辑,新增配置热更新与自动迁移支持,升级相关依赖

This commit is contained in:
2026-01-27 12:20:51 +08:00
parent 89b7f1ae3a
commit cfd7c605af
7 changed files with 66 additions and 12 deletions

View File

@@ -14,6 +14,7 @@ import (
"BingPaper/internal/http/handlers"
"BingPaper/internal/http/middleware"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
@@ -22,6 +23,14 @@ import (
func SetupRouter(webFS embed.FS) *gin.Engine {
r := gin.Default()
// CORS 配置:更宽松的配置以解决 Vue 等前端的预检请求问题
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true
corsConfig.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
corsConfig.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization", "Accept", "X-Requested-With"}
corsConfig.AllowCredentials = true
r.Use(cors.New(corsConfig))
// Swagger
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))