-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove a whole pile of startup indirection
fixes #360
- Loading branch information
Showing
7 changed files
with
363 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ctrladmin | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"go.senan.xyz/gonic/server/ctrladmin/adminui" | ||
) | ||
|
||
func AddRoutes(c *Controller, r *mux.Router) { | ||
// public routes (creates session) | ||
r.Use(c.WithSession) | ||
r.Handle("/login", c.H(c.ServeLogin)) | ||
r.Handle("/login_do", c.HR(c.ServeLoginDo)) // "raw" handler, updates session | ||
|
||
staticHandler := http.StripPrefix("/admin", http.FileServer(http.FS(adminui.StaticFS))) | ||
r.PathPrefix("/static").Handler(staticHandler) | ||
|
||
// user routes (if session is valid) | ||
routUser := r.NewRoute().Subrouter() | ||
routUser.Use(c.WithUserSession) | ||
routUser.Handle("/logout", c.HR(c.ServeLogout)) // "raw" handler, updates session | ||
routUser.Handle("/home", c.H(c.ServeHome)) | ||
routUser.Handle("/change_username", c.H(c.ServeChangeUsername)) | ||
routUser.Handle("/change_username_do", c.H(c.ServeChangeUsernameDo)) | ||
routUser.Handle("/change_password", c.H(c.ServeChangePassword)) | ||
routUser.Handle("/change_password_do", c.H(c.ServeChangePasswordDo)) | ||
routUser.Handle("/change_avatar", c.H(c.ServeChangeAvatar)) | ||
routUser.Handle("/change_avatar_do", c.H(c.ServeChangeAvatarDo)) | ||
routUser.Handle("/delete_avatar_do", c.H(c.ServeDeleteAvatarDo)) | ||
routUser.Handle("/delete_user", c.H(c.ServeDeleteUser)) | ||
routUser.Handle("/delete_user_do", c.H(c.ServeDeleteUserDo)) | ||
routUser.Handle("/link_lastfm_do", c.H(c.ServeLinkLastFMDo)) | ||
routUser.Handle("/unlink_lastfm_do", c.H(c.ServeUnlinkLastFMDo)) | ||
routUser.Handle("/link_listenbrainz_do", c.H(c.ServeLinkListenBrainzDo)) | ||
routUser.Handle("/unlink_listenbrainz_do", c.H(c.ServeUnlinkListenBrainzDo)) | ||
routUser.Handle("/create_transcode_pref_do", c.H(c.ServeCreateTranscodePrefDo)) | ||
routUser.Handle("/delete_transcode_pref_do", c.H(c.ServeDeleteTranscodePrefDo)) | ||
|
||
// admin routes (if session is valid, and is admin) | ||
routAdmin := routUser.NewRoute().Subrouter() | ||
routAdmin.Use(c.WithAdminSession) | ||
routAdmin.Handle("/create_user", c.H(c.ServeCreateUser)) | ||
routAdmin.Handle("/create_user_do", c.H(c.ServeCreateUserDo)) | ||
routAdmin.Handle("/update_lastfm_api_key", c.H(c.ServeUpdateLastFMAPIKey)) | ||
routAdmin.Handle("/update_lastfm_api_key_do", c.H(c.ServeUpdateLastFMAPIKeyDo)) | ||
routAdmin.Handle("/start_scan_inc_do", c.H(c.ServeStartScanIncDo)) | ||
routAdmin.Handle("/start_scan_full_do", c.H(c.ServeStartScanFullDo)) | ||
routAdmin.Handle("/add_podcast_do", c.H(c.ServePodcastAddDo)) | ||
routAdmin.Handle("/delete_podcast_do", c.H(c.ServePodcastDeleteDo)) | ||
routAdmin.Handle("/download_podcast_do", c.H(c.ServePodcastDownloadDo)) | ||
routAdmin.Handle("/update_podcast_do", c.H(c.ServePodcastUpdateDo)) | ||
routAdmin.Handle("/add_internet_radio_station_do", c.H(c.ServeInternetRadioStationAddDo)) | ||
routAdmin.Handle("/delete_internet_radio_station_do", c.H(c.ServeInternetRadioStationDeleteDo)) | ||
routAdmin.Handle("/update_internet_radio_station_do", c.H(c.ServeInternetRadioStationUpdateDo)) | ||
|
||
// middlewares should be run for not found handler | ||
// https://github.com/gorilla/mux/issues/416 | ||
notFoundHandler := c.H(c.ServeNotFound) | ||
notFoundRoute := r.NewRoute().Handler(notFoundHandler) | ||
r.NotFoundHandler = notFoundRoute.GetHandler() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.