mirror of
https://github.com/status-im/simulation.git
synced 2025-02-20 10:58:23 +00:00
21 lines
574 B
Go
21 lines
574 B
Go
package main
|
|
|
|
import "net/http"
|
|
|
|
func allowCORS(fn func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if origin := r.Header.Get("Access-Control-Allow-Origin"); origin == "" {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
}
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
if origin := r.Header.Get("Origin"); origin != "" {
|
|
if r.Method == "OPTIONS" && r.Header.Get("Access-Control-Request-Method") != "" {
|
|
// set preflight options
|
|
return
|
|
}
|
|
}
|
|
|
|
fn(w, r)
|
|
}
|
|
}
|