option to disable the homepage

This commit is contained in:
mappu 2017-10-15 19:16:22 +13:00
parent 24febefba4
commit 40aa6c8917
2 changed files with 5 additions and 2 deletions

View File

@ -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 {

View File

@ -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,