package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// Cors 跨域配置
func Cors(c *gin.Context) {
	method := c.Request.Method
	c.Header("ACCESS-CONTROL-ALLOW-ORIGIN", "*")
	c.Header("Access-Control-Allow-Headers", "*")
	c.Header("Access-Control-Allow-Methods", "*")
	c.Header("Access-Control-Expose-Headers", "*")
	c.Header("Access-Control-Allow-Credentials", "true")
	if method == "OPTIONS" {
		c.AbortWithStatus(http.StatusNoContent)
		return
	}
	c.Next()
}
