add cors middleware

This commit is contained in:
2023-01-31 23:06:45 -03:00
parent 5fa4d4e78a
commit 2ed4b14cf1
2 changed files with 19 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
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 {
case "http://localhost:5173", "http://localhost", "https://alai.cromer.cl":
writer.Header().Set("Access-Control-Allow-Origin", origin)
writer.Header().Set("Access-Control-Allow-Headers", "Content-Type")
}
})
}