From ddfd257e063bb3af3a40ce75eb658d0581decb8f Mon Sep 17 00:00:00 2001 From: Alex Guo Date: Thu, 20 May 2021 20:03:01 -0500 Subject: [PATCH] CORS: set Access-Control-Allow-Origin to * for all responses --- code/go/0chain.net/core/common/handler.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/go/0chain.net/core/common/handler.go b/code/go/0chain.net/core/common/handler.go index 71b933456..f84af02e6 100644 --- a/code/go/0chain.net/core/common/handler.go +++ b/code/go/0chain.net/core/common/handler.go @@ -39,6 +39,7 @@ type JSONReqResponderF func(ctx context.Context, json map[string]interface{}) (i /*Respond - respond either data or error as a response */ func Respond(w http.ResponseWriter, data interface{}, err error) { + w.Header().Set("Access-Control-Allow-Origin", "*") // CORS for all. w.Header().Set("Content-Type", "application/json") if err != nil { data := make(map[string]interface{}, 2) @@ -105,6 +106,7 @@ func SetupCORSResponse(w http.ResponseWriter, r *http.Request) { */ func ToJSONResponse(handler JSONResponderF) ReqRespHandlerf { return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Origin", "*") // CORS for all. if r.Method == "OPTIONS" { SetupCORSResponse(w, r) return