MCPcopy Create free account
hub / github.com/codealong-dev/ride-sharing / enableCORS

Function enableCORS

services/api-gateway/middleware.go:5–19  ·  view source on GitHub ↗
(handler http.HandlerFunc)

Source from the content-addressed store, hash-verified

3import "net/http"
4
5func enableCORS(handler http.HandlerFunc) http.HandlerFunc {
6 return func(w http.ResponseWriter, r *http.Request) {
7 w.Header().Set("Access-Control-Allow-Origin", "*")
8 w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
9 w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
10
11 // allow preflight requests from the browser API
12 if r.Method == "OPTIONS" {
13 w.WriteHeader(http.StatusOK)
14 return
15 }
16
17 handler(w, r)
18 }
19}

Callers 1

mainFunction · 0.85

Calls 1

SetMethod · 0.80

Tested by

no test coverage detected