Files
spend-sparrow/middleware/cors.go

23 lines
470 B
Go

package middleware
import (
"me-fit/types"
"net/http"
)
func EnableCors(serverSettings *types.ServerSettings, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", serverSettings.BaseUrl)
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}