diff --git a/abyss.go b/abyss.go index a604af9..3119db6 100644 --- a/abyss.go +++ b/abyss.go @@ -51,7 +51,7 @@ func main() { } mux := http.NewServeMux() - mux.HandleFunc("/", app.fileHandler) + mux.HandleFunc("/", app.indexHandler) mux.HandleFunc( "/tree/", app.basicAuth(app.treeHandler), diff --git a/handlers.go b/handlers.go index ba7d8f2..563f06e 100644 --- a/handlers.go +++ b/handlers.go @@ -22,7 +22,11 @@ type Application struct { port string } -func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) { +func (app *Application) treeHandler(w http.ResponseWriter, r *http.Request) { + http.StripPrefix("/tree/", http.FileServer(http.Dir(app.filesDir))).ServeHTTP(w, r) +} + +func (app *Application) indexHandler(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { app.uploadHandler(w, r) return @@ -39,14 +43,10 @@ func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) { if fileInfo, err := os.Stat(path); err == nil && !fileInfo.IsDir() { http.ServeFile(w, r, path) } else { - http.NotFound(w, r) + http.StripPrefix("/", http.FileServer(http.Dir("static"))).ServeHTTP(w, r) } } -func (app *Application) treeHandler(w http.ResponseWriter, r *http.Request) { - http.StripPrefix("/tree/", http.FileServer(http.Dir(app.filesDir))).ServeHTTP(w, r) -} - func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.Error(w, "Method not allowed", http.StatusUnauthorized)