remove a whole pile of startup indirection

fixes #360
This commit is contained in:
sentriz
2023-09-11 23:47:09 +01:00
parent 749233db4e
commit b3199de967
7 changed files with 365 additions and 508 deletions

34
server/ctrlbase/routes.go Normal file
View File

@@ -0,0 +1,34 @@
package ctrlbase
import (
"fmt"
"net/http"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func AddRoutes(c *Controller, r *mux.Router, logHTTP bool) {
if logHTTP {
r.Use(c.WithLogging)
}
r.Use(c.WithCORS)
r.Use(handlers.RecoveryHandler(handlers.PrintRecoveryStack(true)))
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
adminHome := c.Path("/admin/home")
http.Redirect(w, r, adminHome, http.StatusSeeOther)
})
// misc subsonic routes without /rest prefix
r.HandleFunc("/settings.view", func(w http.ResponseWriter, r *http.Request) {
adminHome := c.Path("/admin/home")
http.Redirect(w, r, adminHome, http.StatusSeeOther)
})
r.HandleFunc("/musicFolderSettings.view", func(w http.ResponseWriter, r *http.Request) {
restScan := c.Path(fmt.Sprintf("/rest/startScan.view?%s", r.URL.Query().Encode()))
http.Redirect(w, r, restScan, http.StatusSeeOther)
})
r.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK")
})
}