Files
InfoGenie/infogenie-backend-go/internal/middleware/cors.go
2026-03-28 20:59:52 +08:00

24 lines
771 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package middleware
import (
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
// CORS 宽松策略:放行任意 Origin由 gin-contrib/cors 回显请求 Origin便于前后端分离域名部署。
// 如需收紧,可改为仅白名单或仅允许 https://infogenie.shumengya.top 等。
func CORS() gin.HandlerFunc {
return cors.New(cors.Config{
AllowOriginFunc: func(origin string) bool {
return true
},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization", "Accept", "X-Site-Admin-Token"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}