alai-server/backend/middlewares/cors.go

21 lines
665 B
Go
Raw Permalink Normal View History

2023-01-31 23:06:45 -03:00
package middlewares
import (
"net/http"
)
func Cors(handler http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
origin := request.Header.Get("Origin")
switch origin {
2023-01-31 23:39:05 -03:00
case "http://localhost:5173", "http://localhost:4173", "http://localhost", "https://alai.cromer.cl":
2023-01-31 23:06:45 -03:00
writer.Header().Set("Access-Control-Allow-Origin", origin)
2023-01-31 23:34:04 -03:00
writer.Header().Set("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT,DELETE,PATCH")
writer.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
2023-01-31 23:06:45 -03:00
}
2023-01-31 23:22:13 -03:00
handler.ServeHTTP(writer, request)
2023-01-31 23:06:45 -03:00
})
}