From b5a29daacaae495d6801dfff0d4fb7a6dfac9f0c Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Thu, 30 May 2019 09:29:50 +0200 Subject: [PATCH] Add maintenance page --- init/conf/config.go | 11 +++++++---- res/template/maintenance.html | 33 +++++++++++++++++++++++++++++++++ webcontroller/web_controller.go | 14 ++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 res/template/maintenance.html diff --git a/init/conf/config.go b/init/conf/config.go index d0491a2..0040027 100644 --- a/init/conf/config.go +++ b/init/conf/config.go @@ -6,12 +6,15 @@ type PixelWebConfig struct { StaticResourceDir string `toml:"static_resource_dir"` TemplateDir string `toml:"template_dir"` DebugMode bool `toml:"debug_mode"` + MaintenanceMode bool `toml:"maintenance_mode"` } const DefaultConfig = `# Pixeldrain Web UI server configuration -api_url_external = "https://sia.pixeldrain.com/api" # Used in the web browser, should be a full URL. Not ending with a slash -api_url_internal = "http://127.0.0.1:8080/api" # Used for internal API requests to the pixeldrain server, not visible to users +api_url_external = "https://sia.pixeldrain.com/api" # Used in the web browser, should be a full URL. Not ending with a slash +api_url_internal = "http://127.0.0.1:8080/api" # Used for internal API requests to the pixeldrain server, not visible to users static_resource_dir = "res/static" -template_dir = "res/template" -debug_mode = false` +template_dir = "res/template" +debug_mode = false +maintenance_mode = false +` diff --git a/res/template/maintenance.html b/res/template/maintenance.html new file mode 100644 index 0000000..d581f38 --- /dev/null +++ b/res/template/maintenance.html @@ -0,0 +1,33 @@ +{{define "maintenance"}} + + + {{template "meta_tags" "Maintenance"}} + {{template "user_style" .}} + + + + Header image +
+
+ +

+ This means the website has temporarily been taken down to apply + changes which cannot be applied in the background (probably a + database upgrade). +

+

+ The website should be back online shortly. You can check out + my Twitter to get a + feeling for when the website will be back up. +

+

+ I'm sorry for the inconvenience. +

+ {{template "footer"}} +
+ {{template "analytics"}} + + +{{end}} diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index 3ff33c3..72c90de 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -48,10 +48,20 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon fs.ServeHTTP(w, r) }) - // General navigation - r.GET(p+"/" /* */, wc.serveTemplate("home", false)) + // Static assets r.GET(p+"/favicon.ico" /* */, wc.serveFile("/favicon.ico")) r.GET(p+"/robots.txt" /* */, wc.serveFile("/robots.txt")) + + if conf.MaintenanceMode { + r.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusServiceUnavailable) + wc.templates.Get().ExecuteTemplate(w, "maintenance", wc.newTemplateData(w, r)) + }) + return wc + } + + // General navigation + r.GET(p+"/" /* */, wc.serveTemplate("home", false)) r.GET(p+"/api" /* */, wc.serveTemplate("apidoc", false)) r.GET(p+"/history" /* */, wc.serveTemplate("history_cookies", false)) r.GET(p+"/u/:id" /* */, wc.serveFileViewer)