godash/handlers/routes.go

35 lines
951 B
Go
Raw Normal View History

2024-03-12 15:49:08 +01:00
package handlers
import (
"net/http"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/r3labs/sse/v2"
)
2024-03-18 21:54:35 +01:00
func SetupRoutes(e *echo.Echo, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) {
2024-03-19 11:36:09 +01:00
if authHandler.env.LogtoEndpoint != "" {
e.GET("/sign-in", authHandler.signInHandler)
e.GET("/sign-in-callback", authHandler.signInCallbackHandler)
e.GET("/sign-out", authHandler.signOutCallbackHandler)
}
secure := e.Group("/")
if authHandler.env.LogtoEndpoint != "" {
secure = e.Group("/", authHandler.logtoMiddleware)
}
2024-03-18 21:54:35 +01:00
secure.GET("", appHandler.appHandler)
secure.GET("sse", echo.WrapHandler(http.HandlerFunc(sse.ServeHTTP)))
secure.Static("", "assets")
secure.Static("storage/icons", "storage/icons")
2024-03-12 15:49:08 +01:00
}
func renderView(c echo.Context, cmp templ.Component) error {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
return cmp.Render(c.Request().Context(), c.Response().Writer)
}