diff options
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -12,12 +12,18 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/rs/cors" + "gitlab.com/gitlab-org/gitlab-pages/metrics" ) const xForwardedProto = "X-Forwarded-Proto" const xForwardedProtoHTTPS = "https" +var ( + corsHandler = cors.New(cors.Options{AllowedMethods: []string{"GET"}}) +) + type theApp struct { appConfig domains domains @@ -73,8 +79,13 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo return } - // Serve static file - domain.ServeHTTP(&w, r) + // Serve static file, applying CORS headers if necessary + if a.DisableCrossOriginRequests { + domain.ServeHTTP(&w, r) + } else { + corsHandler.ServeHTTP(&w, r, domain.ServeHTTP) + } + metrics.ProcessedRequests.WithLabelValues(strconv.Itoa(w.status), r.Method).Inc() } |