pcmt/app/routes.go
leo c4d0cb209b
All checks were successful
continuous-integration/drone/push Build is passing
go: add settings struct
* let the settings struct be the single source of truth
* rm app fields that are covered by settings
* pass around a pointer to settings instead of config
* consolidate config+flags into settings on start-up
* update tests
* rm empty settings.go file

fixes #4
2023-05-03 02:18:29 +02:00

45 lines
1.2 KiB
Go

package app
import (
"net/http"
"git.dotya.ml/mirre-mt/pcmt/handlers"
"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()
// run this before declaring any handler funcs.
handlers.InitHandlers(setting, tmpls)
// 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("/", 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())
e.GET("/logout", handlers.Logout())
e.POST("/logout", handlers.Logout())
// administrative endpoints.
e.GET("/admin/*", handlers.Admin())
}