Make router better

This commit is contained in:
Florian Hoss 2024-04-04 09:37:28 +02:00
parent 73fbe6c3f7
commit 68ff409afc
2 changed files with 11 additions and 7 deletions

View file

@ -44,6 +44,10 @@ type AppHandler struct {
}
func (bh *AppHandler) appHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Redirect(w, r, "/", http.StatusFound)
return
}
bookmarks := bh.bookmarkService.GetAllBookmarks()
staticSystem := bh.systemService.GetStaticInformation()
liveSystem := bh.systemService.GetLiveInformation()

View file

@ -8,17 +8,17 @@ import (
func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) {
if authHandler.sessionManager != nil {
router.HandleFunc("/sign-in", authHandler.signInHandler)
router.HandleFunc("/sign-in-callback", authHandler.signInCallbackHandler)
router.HandleFunc("/sign-out", authHandler.signOutHandler)
router.HandleFunc("GET /sign-in", authHandler.signInHandler)
router.HandleFunc("GET /sign-in-callback", authHandler.signInCallbackHandler)
router.HandleFunc("GET /sign-out", authHandler.signOutHandler)
}
router.Handle("/sse", authHandler.authRequired(http.HandlerFunc(sse.ServeHTTP)))
router.Handle("GET /sse", authHandler.authRequired(http.HandlerFunc(sse.ServeHTTP)))
fsAssets := http.FileServer(http.Dir("assets"))
router.Handle("/assets/", authHandler.authRequired(http.StripPrefix("/assets/", fsAssets)))
router.Handle("GET /assets/", authHandler.authRequired(http.StripPrefix("/assets/", fsAssets)))
fsIcons := http.FileServer(http.Dir("storage/icons"))
router.Handle("/storage/icons/", authHandler.authRequired(http.StripPrefix("/storage/icons/", fsIcons)))
router.Handle("GET /storage/icons/", authHandler.authRequired(http.StripPrefix("/storage/icons/", fsIcons)))
router.Handle("/", authHandler.authRequired(http.HandlerFunc(appHandler.appHandler)))
router.Handle("GET /", authHandler.authRequired(http.HandlerFunc(appHandler.appHandler)))
}