Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
Diffstat (limited to 'app.go')
-rw-r--r--app.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/app.go b/app.go
index 59912bb1..7e63a802 100644
--- a/app.go
+++ b/app.go
@@ -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()
}