mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
24 lines
632 B
Go
24 lines
632 B
Go
package middlewares
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab/core/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
func CORSMiddleware() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
c.Writer.Header().Set("Access-Control-Allow-Origin", utils.GetAllowOrigin())
|
|
c.Writer.Header().Set("Access-Control-Allow-Credentials", utils.GetAllowCredentials())
|
|
c.Writer.Header().Set("Access-Control-Allow-Headers", utils.GetAllowHeaders())
|
|
c.Writer.Header().Set("Access-Control-Allow-Methods", utils.GetAllowMethods())
|
|
|
|
if c.Request.Method == "OPTIONS" {
|
|
c.AbortWithStatus(http.StatusNoContent)
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
}
|