|
| @@ -8,29 +8,34 @@ import ( |
| 8 | | "github.com/labstack/echo/v4" | 8 | | "github.com/labstack/echo/v4" |
| 9 | | ) | 9 | | ) |
| 10 | | | 10 | | |
| 11 | - | // RegisterRoutes registers all routes for the application | 11 | + | // RegisterRoutes registers all routes and middlewares |
| 12 | | func RegisterRoutes(e *echo.Echo, a *server.App) *echo.Echo { | 12 | | func RegisterRoutes(e *echo.Echo, a *server.App) *echo.Echo { |
| | | 13 | + | // Initiate the session middleware |
| | | 14 | + | e.Use(middleware.InitSessionMiddleware(a)) |
| | | 15 | + | |
| | | 16 | + | // Language detection |
| | | 17 | + | e.Use(middleware.LanguageDetection) |
| | | 18 | + | |
| 13 | | AdminPath := a.Config.Admin.Path | 19 | | AdminPath := a.Config.Admin.Path |
| 14 | | bindLoginRoute(e, a, AdminPath) | 20 | | bindLoginRoute(e, a, AdminPath) |
| 15 | | bindAPIEndpoints(e, a) | 21 | | bindAPIEndpoints(e, a) |
| 16 | | | 22 | | |
| 17 | | // SetCommonDataMiddleware will pass data to the renderer | 23 | | // SetCommonDataMiddleware will pass data to the renderer |
| 18 | | e.Use(middleware.SetCommonDataMiddleware(a)) | 24 | | e.Use(middleware.SetCommonDataMiddleware(a)) |
| | | 25 | + | |
| 19 | | // Error handler middleware | 26 | | // Error handler middleware |
| 20 | | e.Use(middleware.ErrorHandler) | 27 | | e.Use(middleware.ErrorHandler) |
| 21 | - | // Initiate the session middleware | 28 | + | |
| 22 | - | e.Use(middleware.InitSessionMiddleware(a)) | | | |
| 23 | | // Use middlewares | 29 | | // Use middlewares |
| 24 | | e.Use(middleware.SecureRoutes()) | 30 | | e.Use(middleware.SecureRoutes()) |
| | | 31 | + | |
| 25 | | // Color scheme detection for dark/light mode | 32 | | // Color scheme detection for dark/light mode |
| 26 | | e.Use(middleware.ColorSchemeDetection) | 33 | | e.Use(middleware.ColorSchemeDetection) |
| 27 | - | // Language detection | | | |
| 28 | - | e.Use(middleware.LanguageDetection) | | | |
| 29 | | | 34 | | |
| 30 | - | // --- Register routes --- // | | | |
| 31 | | bindAdminRoute(e, a, AdminPath) | 35 | | bindAdminRoute(e, a, AdminPath) |
| 32 | | bindStaticRoute(e, a, "/*") | 36 | | bindStaticRoute(e, a, "/*") |
| 33 | | bindHTMXEndpoints(e, a) | 37 | | bindHTMXEndpoints(e, a) |
| | | 38 | + | |
| 34 | | // Protect the root path with a 403 | 39 | | // Protect the root path with a 403 |
| 35 | | e.GET("/", func(c echo.Context) error { | 40 | | e.GET("/", func(c echo.Context) error { |
| 36 | | return c.String(403, "403 Forbidden") | 41 | | return c.String(403, "403 Forbidden") |