diff options
author | Kamil TrzciĆski <ayufan@ayufan.eu> | 2017-11-23 20:05:41 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-11-23 20:05:41 +0300 |
commit | 04b1d52ca05f268a63a72181600aa09251b6297a (patch) | |
tree | 0511d284185f68eef3cd7fa3eb2121d20c99ffb5 /app.go | |
parent | 15c938cafbd95064bbc4be34cd72091f9a61edaa (diff) |
Return 503 until pages are loaded for the first time
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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) |