package api import ( "net/http" "github.com/go-chi/cors" ) // Sets up default CORS rules to use as a middleware func handleCORS(next http.Handler) http.Handler { return cors.New(cors.Options{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, AllowCredentials: true, MaxAge: 300, // Maximum value not ignored by any of major browsers }).Handler(next) }