graphicek/server/middleware/cors.go

19 lines
364 B
Go

package middleware
import (
"github.com/gin-gonic/gin"
)
func CorsMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Credentials", "true")
// 2 hours
c.Header("Access-Control-Max-Age", "7200")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(200)
}
}
}