graphicek/server/middleware/cors.go

19 lines
364 B
Go
Raw Normal View History

2022-08-21 22:27:21 +02:00
package middleware
import (
"github.com/gin-gonic/gin"
)
2022-08-21 22:27:21 +02:00
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)
}
2022-08-21 22:27:21 +02:00
}
}