godash/handlers/routes.go

25 lines
924 B
Go
Raw Normal View History

2024-03-12 15:49:08 +01:00
package handlers
import (
"net/http"
"github.com/r3labs/sse/v2"
)
func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) {
2024-04-04 09:25:59 +02:00
if authHandler.sessionManager != nil {
2024-04-04 09:37:28 +02:00
router.HandleFunc("GET /sign-in", authHandler.signInHandler)
router.HandleFunc("GET /sign-in-callback", authHandler.signInCallbackHandler)
router.HandleFunc("GET /sign-out", authHandler.signOutHandler)
2024-03-19 11:36:09 +01:00
}
2024-04-04 09:37:28 +02:00
router.Handle("GET /sse", authHandler.authRequired(http.HandlerFunc(sse.ServeHTTP)))
2024-03-19 11:36:09 +01:00
fsAssets := http.FileServer(http.Dir("assets"))
2024-04-04 09:37:28 +02:00
router.Handle("GET /assets/", authHandler.authRequired(http.StripPrefix("/assets/", fsAssets)))
2024-03-12 15:49:08 +01:00
fsIcons := http.FileServer(http.Dir("storage/icons"))
2024-04-04 09:37:28 +02:00
router.Handle("GET /storage/icons/", authHandler.authRequired(http.StripPrefix("/storage/icons/", fsIcons)))
2024-03-12 15:49:08 +01:00
2024-04-04 09:37:28 +02:00
router.Handle("GET /", authHandler.authRequired(http.HandlerFunc(appHandler.appHandler)))
2024-03-12 15:49:08 +01:00
}