From d99c248a467fb4bfedc08589619a9286536d3544 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 25 Aug 2022 16:46:58 +0300 Subject: [PATCH] [#56] Add Allow-Origin header to all responses Signed-off-by: Denis Kirillov --- handlers/api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handlers/api.go b/handlers/api.go index eb16820..0721b11 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -69,6 +69,8 @@ const ( ContextKeyRequestID ContextKey = "requestID" docsPrefix = "/docs" + + accessControlAllowOriginHeader = "Access-Control-Allow-Origin" ) // New creates a new API using specified logger, connection pool and other parameters. @@ -165,6 +167,8 @@ func (a *API) setupGlobalMiddleware(handler http.Handler) http.Handler { ctx := context.WithValue(r.Context(), ContextKeyRequestID, requestID) + w.Header().Set(accessControlAllowOriginHeader, allOrigins) + handler.ServeHTTP(w, r.WithContext(ctx)) }) }