mirror of
https://github.com/status-im/simulation.git
synced 2025-02-23 20:38:07 +00:00
21 lines
563 B
Go
21 lines
563 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", "*")
|
||
|
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)
|
||
|
}
|
||
|
}
|