Skip to content

Commit 8017d86

Browse files
authored
fix: added cors headers to be part of every response (#151)
1 parent 8e22473 commit 8017d86

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gateway/manager/manager.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,19 @@ func (s *Service) createHandler(schema *graphql.Schema) *graphqlHandler {
190190

191191
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
192192

193-
if (*r).Method == "OPTIONS" && s.appCfg.Cors.Enabled {
193+
if s.appCfg.Cors.Enabled {
194194
allowedOrigins := strings.Join(s.appCfg.Cors.AllowedOrigins, ",")
195195
allowedHeaders := strings.Join(s.appCfg.Cors.AllowedHeaders, ",")
196196
w.Header().Set("Access-Control-Allow-Origin", allowedOrigins)
197197
w.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
198198
// setting cors allowed methods is not needed for this service,
199199
// as all graphql methods are part of the cors safelisted methods
200200
// https://fetch.spec.whatwg.org/#cors-safelisted-method
201-
w.WriteHeader(http.StatusOK)
202-
return
201+
202+
if r.Method == http.MethodOptions {
203+
w.WriteHeader(http.StatusOK)
204+
return
205+
}
203206
}
204207

205208
workspace, err := s.parsePath(r.URL.Path)

0 commit comments

Comments
 (0)