修改项目为前后端分离方案

This commit is contained in:
2026-03-28 23:30:02 +08:00
parent d8536354d4
commit 7a7d3aeaaa
77 changed files with 1447 additions and 23765 deletions

21
middleware/cors.go Normal file
View File

@@ -0,0 +1,21 @@
package middleware
import (
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
// CorsMiddleware 处理跨域请求
// 允许 Vue 等前端分离架构在开发和生产环境下访问后端 API
func CorsMiddleware() gin.HandlerFunc {
return cors.New(cors.Config{
AllowOriginFunc: func(origin string) bool { return true }, // 允许所有来源
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Authorization", "X-CSRF-Token", "Accept"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}