2024-03-12 15:49:08 +01:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/r3labs/sse/v2"
|
|
|
|
)
|
|
|
|
|
2024-04-03 12:17:05 +02:00
|
|
|
func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) {
|
2024-04-12 16:19:11 +02:00
|
|
|
if authHandler != nil {
|
|
|
|
router.Handle("GET /auth/", authHandler.authenticator)
|
|
|
|
|
|
|
|
router.Handle("GET /sse", authHandler.middleware.RequireAuthentication()(http.HandlerFunc(sse.ServeHTTP)))
|
|
|
|
|
|
|
|
fsAssets := http.FileServer(http.Dir("assets"))
|
|
|
|
router.Handle("GET /assets/", authHandler.middleware.RequireAuthentication()(http.StripPrefix("/assets/", fsAssets)))
|
2024-03-19 11:36:09 +01:00
|
|
|
|
2024-04-12 16:19:11 +02:00
|
|
|
fsIcons := http.FileServer(http.Dir("storage/icons"))
|
|
|
|
router.Handle("GET /storage/icons/", authHandler.middleware.RequireAuthentication()(http.StripPrefix("/storage/icons/", fsIcons)))
|
2024-03-12 15:49:08 +01:00
|
|
|
|
2024-04-12 16:19:11 +02:00
|
|
|
router.Handle("GET /", authHandler.middleware.RequireAuthentication()(http.HandlerFunc(appHandler.appHandler)))
|
|
|
|
} else {
|
|
|
|
router.HandleFunc("GET /sse", sse.ServeHTTP)
|
2024-03-12 15:49:08 +01:00
|
|
|
|
2024-04-12 16:19:11 +02:00
|
|
|
fsAssets := http.FileServer(http.Dir("assets"))
|
|
|
|
router.Handle("GET /assets/", http.StripPrefix("/assets/", fsAssets))
|
|
|
|
|
|
|
|
fsIcons := http.FileServer(http.Dir("storage/icons"))
|
|
|
|
router.Handle("GET /storage/icons/", http.StripPrefix("/storage/icons/", fsIcons))
|
|
|
|
|
|
|
|
router.HandleFunc("GET /", appHandler.appHandler)
|
|
|
|
}
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|