mercury/web/routes.go

35 lines
919 B
Go
Raw Normal View History

2023-09-03 00:23:48 +02:00
package web
import (
"git.sleepycat.moe/sam/mercury/web/app"
2023-09-03 04:11:56 +02:00
"git.sleepycat.moe/sam/mercury/web/auth"
2023-09-03 00:23:48 +02:00
"git.sleepycat.moe/sam/mercury/web/frontend"
2023-09-03 04:11:56 +02:00
"github.com/go-chi/chi/v5"
2023-09-03 00:23:48 +02:00
)
func Routes(app *app.App) {
2023-09-03 04:11:56 +02:00
// auth
app.Router.Route("/auth", func(r chi.Router) {
auth := auth.New(app)
r.Get("/login", auth.GetLogin)
2023-09-04 03:33:13 +02:00
r.Post("/login", auth.PostLogin)
r.Get("/sign_up", auth.GetSignup)
r.Post("/sign_up", auth.PostSignup)
2023-09-03 04:11:56 +02:00
})
// web app handlers
// also assets
2023-09-04 03:33:13 +02:00
app.Router.Group(func(r chi.Router) {
frontend := frontend.New(app)
r.Use(app.FrontendAuth)
2023-09-04 03:33:13 +02:00
r.HandleFunc(frontend.AssetsPath(), frontend.ServeAssets)
r.HandleFunc("/static/*", frontend.ServeStaticAssets)
r.HandleFunc("/web", frontend.ServeFrontend)
r.HandleFunc("/web/*", frontend.ServeFrontend)
r.HandleFunc("/web/@{username}", frontend.ServeUser)
r.HandleFunc("/web/@{username}/posts/{postID}", frontend.ServeStatus)
2023-09-04 03:33:13 +02:00
})
2023-09-03 00:23:48 +02:00
}