Some checks failed
CI/CD Pipeline / Test (push) Failing after 22m19s
CI/CD Pipeline / Security Scan (push) Failing after 5m57s
CI/CD Pipeline / Build (amd64, darwin) (push) Has been skipped
CI/CD Pipeline / Build (amd64, linux) (push) Has been skipped
CI/CD Pipeline / Build (amd64, windows) (push) Has been skipped
CI/CD Pipeline / Build (arm64, darwin) (push) Has been skipped
CI/CD Pipeline / Build (arm64, linux) (push) Has been skipped
CI/CD Pipeline / Build Docker Image (push) Has been skipped
CI/CD Pipeline / Create Release (push) Has been skipped
17 lines
439 B
Go
17 lines
439 B
Go
package middleware
|
||
|
||
import (
|
||
"github.com/gofiber/fiber/v2"
|
||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||
)
|
||
|
||
// SetupCORS 设置CORS中间件
|
||
// 配置跨域资源共享,允许前端应用访问API
|
||
func SetupCORS() fiber.Handler {
|
||
return cors.New(cors.Config{
|
||
AllowOrigins: "*",
|
||
AllowMethods: "GET, POST, PUT, DELETE, OPTIONS",
|
||
AllowHeaders: "Origin, Content-Type, Accept, Authorization",
|
||
MaxAge: 86400, // 24小时
|
||
})
|
||
} |