From 40aa6c8917cc9779739159021d9dc0dcb5749f9e Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 15 Oct 2017 19:16:22 +1300 Subject: [PATCH] option to disable the homepage --- Server.go | 5 +++-- cmd/contented/main.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Server.go b/Server.go index f738576..513f755 100644 --- a/Server.go +++ b/Server.go @@ -24,6 +24,7 @@ type ServerOptions struct { DBPath string BandwidthLimit int64 TrustXForwardedFor bool + EnableHomepage bool ServerPublicProperties } @@ -119,10 +120,10 @@ func (this *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Blanket allow (headers already set) w.WriteHeader(200) - } else if r.Method == "GET" && r.URL.Path == `/` { + } else if r.Method == "GET" && r.URL.Path == `/` && this.opts.EnableHomepage { http.Redirect(w, r, `/index.html`, http.StatusFound) - } else if static, err := Asset(r.URL.Path[1:]); err == nil && r.Method == "GET" { + } else if static, err := Asset(r.URL.Path[1:]); err == nil && r.Method == "GET" && (this.opts.EnableHomepage || r.URL.Path != `/index.html`) { http.ServeContent(w, r, r.URL.Path[1:], this.startTime, bytes.NewReader(static)) } else { diff --git a/cmd/contented/main.go b/cmd/contented/main.go index e258129..39a2341 100644 --- a/cmd/contented/main.go +++ b/cmd/contented/main.go @@ -19,6 +19,7 @@ func main() { maxUploadMb := flag.Int("max", 8, "Maximum size of uploaded files in MiB (set zero for unlimited)") maxUploadSpeed := flag.Int("speed", 0, "Maximum upload speed in bytes/sec (set zero for unlimited)") trustXForwardedFor := flag.Bool("trustXForwardedFor", false, "Trust X-Forwarded-For reverse proxy headers") + enableHomepage := flag.Bool("enableHomepage", true, "Enable homepage (disable for embedded use only)") flag.Parse() @@ -27,6 +28,7 @@ func main() { DBPath: *dbPath, BandwidthLimit: int64(*maxUploadSpeed), TrustXForwardedFor: *trustXForwardedFor, + EnableHomepage: *enableHomepage, ServerPublicProperties: contented.ServerPublicProperties{ AppTitle: *appTitle, MaxUploadBytes: int64(*maxUploadMb) * 1024 * 1024,