12345678910111213141516171819202122 |
- package controller
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "net/http"
- )
- func Cors(c *gin.Context) {
- method := c.Request.Method
- c.Header("Access-Control-Allow-Origin", c.GetHeader("Origin"))
- fmt.Println(c.GetHeader("Origin"))
- c.Header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS")
- c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Token")
- c.Header("Access-Control-Expose-Headers", "Access-Control-Allow-Headers, Token")
- c.Header("Access-Control-Allow-Credentials", "true")
- if method == "OPTIONS" {
- c.AbortWithStatus(http.StatusNoContent)
- return
- }
- c.Next()
- }
|