2023-03-22 23:03:21 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-03-22 23:11:14 +01:00
|
|
|
"git.dotya.ml/mirre-mt/pcmt/handlers"
|
2023-03-22 23:03:21 +01:00
|
|
|
"github.com/labstack/echo/v4"
|
2023-04-26 22:44:18 +02:00
|
|
|
"github.com/labstack/echo/v4/middleware"
|
2023-03-22 23:03:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *App) SetupRoutes() {
|
|
|
|
e := a.E()
|
2023-05-03 02:18:29 +02:00
|
|
|
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
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
// run this before declaring any handler funcs.
|
2023-05-03 02:18:29 +02:00
|
|
|
handlers.InitHandlers(setting, tmpls)
|
2023-05-06 21:50:35 +02:00
|
|
|
e.Renderer = handlers.Renderer
|
2023-04-13 00:07:08 +02:00
|
|
|
|
2023-04-26 22:44:18 +02:00
|
|
|
// keep /static/* as a compatibility fallback for /assets.
|
|
|
|
e.GET(
|
|
|
|
"/static/*",
|
2023-04-27 17:43:34 +02:00
|
|
|
func(c echo.Context) error {
|
2023-04-28 19:07:43 +02:00
|
|
|
return c.Redirect(http.StatusMovedPermanently, c.Request().URL.Path)
|
2023-04-27 17:43:34 +02:00
|
|
|
},
|
2023-04-26 22:44:18 +02:00
|
|
|
middleware.Rewrite(
|
|
|
|
map[string]string{"/static/*": "/assets/$1"},
|
|
|
|
),
|
|
|
|
)
|
2023-04-27 17:43:34 +02:00
|
|
|
// alternative:
|
|
|
|
// e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assets)))
|
2023-04-26 22:44:18 +02:00
|
|
|
e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/assets/", assets)))
|
2023-04-13 00:07:08 +02:00
|
|
|
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))
|
2023-05-06 00:03:41 +02:00
|
|
|
e.GET("/home", handlers.Home(a.db))
|
2023-04-13 00:07:08 +02:00
|
|
|
e.GET("/logout", handlers.Logout())
|
|
|
|
e.POST("/logout", handlers.Logout())
|
2023-03-22 23:11:14 +01:00
|
|
|
|
|
|
|
// administrative endpoints.
|
2023-04-13 00:07:08 +02:00
|
|
|
e.GET("/admin/*", handlers.Admin())
|
2023-03-22 23:03:21 +01:00
|
|
|
}
|