| 1234567891011121314151617 |
- package middleware
- import (
- "github.com/gin-contrib/cors"
- "github.com/gin-gonic/gin"
- )
- // Cors 跨域配置
- func Cors() gin.HandlerFunc {
- config := cors.DefaultConfig()
- config.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
- config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Cookie", "Token", "Authorization"}
- config.ExposeHeaders = []string{"Origin", "Content-Length", "Content-Type", "Cookie", "Token"}
- config.AllowOrigins = []string{"*"}
- config.AllowCredentials = true
- return cors.New(config)
- }
|