step one
This commit is contained in:
parent
7a8d5d13fa
commit
9e663db9dc
68 changed files with 5647 additions and 2958 deletions
20
internal/api/middleware/cors.go
Normal file
20
internal/api/middleware/cors.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package middleware
|
||||
|
||||
import "net/http"
|
||||
|
||||
// CORS wraps next with permissive CORS headers and short-circuits OPTIONS preflight.
|
||||
//
|
||||
// This service is meant to sit behind an authenticated gateway, so we set
|
||||
// "Access-Control-Allow-Origin: *". Tighten this if you deploy elsewhere.
|
||||
func CORS(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue