refactor mux path routes

legend has it that if you refactor your code enough times, one day you
will finally be happy
This commit is contained in:
ari melody 2025-11-07 17:48:06 +00:00
parent 82fd17c836
commit 21912d4ec2
Signed by: ari
GPG key ID: CF99829C92678188
17 changed files with 102 additions and 469 deletions

24
main.go
View file

@ -517,7 +517,15 @@ func main() {
go cursor.StartCursor(&app)
// start the web server!
mux := createServeMux(&app)
mux := http.NewServeMux()
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler(&app)))
mux.Handle("/api/", http.StripPrefix("/api", api.Handler(&app)))
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(&app)))
mux.Handle("/blog/", http.StripPrefix("/blog", view.BlogHandler(&app)))
mux.Handle("/uploads/", http.StripPrefix("/uploads", view.ServeFiles(filepath.Join(app.Config.DataDirectory, "uploads"))))
mux.Handle("/cursor-ws", cursor.Handler(&app))
mux.Handle("/", view.IndexHandler(&app))
fmt.Printf("Now serving at http://%s:%d\n", app.Config.Host, app.Config.Port)
stdLog.Fatal(
http.ListenAndServe(fmt.Sprintf("%s:%d", app.Config.Host, app.Config.Port),
@ -525,20 +533,6 @@ func main() {
))
}
func createServeMux(app *model.AppState) *http.ServeMux {
mux := http.NewServeMux()
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler(app)))
mux.Handle("/api/", http.StripPrefix("/api", api.Handler(app)))
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(app)))
mux.Handle("/blog/", http.StripPrefix("/blog", view.BlogHandler(app)))
mux.Handle("/uploads/", http.StripPrefix("/uploads", view.ServeFiles(filepath.Join(app.Config.DataDirectory, "uploads"))))
mux.Handle("/cursor-ws", cursor.Handler(app))
mux.Handle("/", view.IndexHandler(app))
return mux
}
var PoweredByStrings = []string{
"nerd rage",
"estrogen",