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:
authorKamil TrzciƄski <ayufan@ayufan.eu>2017-11-23 20:05:41 +0300
committerNick Thomas <nick@gitlab.com>2017-11-23 20:05:41 +0300
commit04b1d52ca05f268a63a72181600aa09251b6297a (patch)
tree0511d284185f68eef3cd7fa3eb2121d20c99ffb5 /app.go
parent15c938cafbd95064bbc4be34cd72091f9a61edaa (diff)
Return 503 until pages are loaded for the first time
Diffstat (limited to 'app.go')
-rw-r--r--app.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/app.go b/app.go
index 3714582a..afc43466 100644
--- a/app.go
+++ b/app.go
@@ -33,6 +33,10 @@ type theApp struct {
Artifact *artifact.Artifact
}
+func (a *theApp) isReady() bool {
+ return a.domains != nil
+}
+
func (a *theApp) domain(host string) *domain {
host = strings.ToLower(host)
a.lock.RLock()
@@ -54,6 +58,14 @@ func (a *theApp) ServeTLS(ch *tls.ClientHelloInfo) (*tls.Certificate, error) {
return nil, nil
}
+func (a *theApp) healthCheck(w http.ResponseWriter, r *http.Request, https bool) {
+ if a.isReady() {
+ w.Write([]byte("success"))
+ } else {
+ http.Error(w, "not yet ready", http.StatusServiceUnavailable)
+ }
+}
+
func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https bool) {
w := newLoggingResponseWriter(ww)
defer w.Log(r)
@@ -63,7 +75,7 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo
// short circuit content serving to check for a status page
if r.RequestURI == a.appConfig.StatusPath {
- w.Write([]byte("success"))
+ a.healthCheck(&w, r, https)
return
}
@@ -89,6 +101,11 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo
return
}
+ if !a.isReady() {
+ httperrors.Serve503(&w)
+ return
+ }
+
domain := a.domain(host)
if domain == nil {
httperrors.Serve404(&w)