leo
ae5c4f1dd4
All checks were successful
continuous-integration/drone/push Build is passing
* add tmpl * add handler for route /manage/user/:id * add convenience helper func * handle not found/invalid uuid errors
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.dotya.ml/mirre-mt/pcmt/handlers"
|
|
modtmpl "git.dotya.ml/mirre-mt/pcmt/modules/template"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
)
|
|
|
|
func (a *App) SetupRoutes() {
|
|
e := a.E()
|
|
setting := a.setting
|
|
assets := http.FileServer(a.getAssets())
|
|
tmpls := a.getTemplates()
|
|
|
|
modtmpl.Init(setting, tmpls)
|
|
// 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)))
|
|
|
|
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))
|
|
|
|
e.GET("/manage/users", handlers.ManageUsers(a.db))
|
|
e.GET("/manage/users/new", handlers.ManageUsers(a.db))
|
|
e.GET("/manage/users/:id", handlers.ViewUser(a.db))
|
|
e.POST("/manage/users/create", handlers.CreateUser(a.db))
|
|
|
|
e.GET("/logout", handlers.Logout())
|
|
e.POST("/logout", handlers.Logout())
|
|
|
|
// administrative endpoints.
|
|
e.GET("/admin/*", handlers.Admin())
|
|
}
|