pcmt/app/routes.go

63 lines
1.8 KiB
Go
Raw Normal View History

2023-05-20 20:15:57 +02:00
// Copyright 2023 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: AGPL-3.0-only
2023-03-22 23:03:21 +01:00
package app
import (
"net/http"
"git.dotya.ml/mirre-mt/pcmt/handlers"
modtmpl "git.dotya.ml/mirre-mt/pcmt/modules/template"
2023-03-22 23:03:21 +01:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
2023-03-22 23:03:21 +01:00
)
func (a *App) SetupRoutes() {
e := a.E()
setting := a.setting
2023-04-26 23:11:58 +02:00
assets := http.FileServer(a.getAssets())
tmpls := a.getTemplates()
2023-03-22 23:03:21 +01:00
modtmpl.Init(setting, tmpls)
handlers.SetDBClient(a.db)
// run this before declaring any handler funcs.
handlers.InitHandlers(setting)
e.Renderer = modtmpl.Renderer
// keep /static/* as a compatibility fallback for /assets.
e.GET(
"/static/*",
func(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, c.Request().URL.Path)
},
middleware.Rewrite(
map[string]string{"/static/*": "/assets/$1"},
),
)
// alternative:
// e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assets)))
e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/assets/", assets)), handlers.MiddlewareCache)
2023-05-13 22:33:38 +02:00
e.GET("/healthz", handlers.Healthz())
e.GET("/health", handlers.Healthz())
e.GET("/", handlers.Index())
e.GET("/signin", handlers.Signin())
e.POST("/signin", handlers.SigninPost(a.db))
e.GET("/signup", handlers.Signup())
e.POST("/signup", handlers.SignupPost(a.db))
e.GET("/home", handlers.Home(a.db))
2023-05-22 03:22:58 +02:00
e.GET("/manage/users", handlers.ManageUsers(), handlers.MiddlewareSession)
e.GET("/manage/users/new", handlers.ManageUsers(), handlers.MiddlewareSession)
e.GET("/manage/users/:id", handlers.ViewUser(), handlers.MiddlewareSession)
e.POST("/manage/users/create", handlers.CreateUser(), handlers.MiddlewareSession)
2023-05-22 03:22:58 +02:00
e.GET("/logout", handlers.Logout())
e.POST("/logout", handlers.Logout())
// administrative endpoints.
e.GET("/admin/*", handlers.Admin())
2023-03-22 23:03:21 +01:00
}