owl-blogs/web/app.go

60 lines
2.0 KiB
Go
Raw Normal View History

2023-06-25 19:32:36 +00:00
package web
import (
"owl-blogs/app"
"github.com/gofiber/fiber/v2"
)
type WebApp struct {
2023-07-06 20:16:52 +00:00
FiberApp *fiber.App
2023-07-07 19:04:25 +00:00
EntryService *app.EntryService
Registry *app.EntryTypeRegistry
2023-06-25 19:32:36 +00:00
}
2023-07-06 20:16:52 +00:00
func NewWebApp(entryService *app.EntryService, typeRegistry *app.EntryTypeRegistry) *WebApp {
2023-06-25 19:32:36 +00:00
app := fiber.New()
indexHandler := NewIndexHandler(entryService)
listHandler := NewListHandler(entryService)
2023-07-07 19:04:25 +00:00
entryHandler := NewEntryHandler(entryService, typeRegistry)
2023-06-25 19:32:36 +00:00
mediaHandler := NewMediaHandler(entryService)
rssHandler := NewRSSHandler(entryService)
loginHandler := NewLoginHandler(entryService)
2023-07-06 20:16:52 +00:00
editorListHandler := NewEditorListHandler(typeRegistry)
editorHandler := NewEditorHandler(entryService, typeRegistry)
2023-06-25 19:32:36 +00:00
// app.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
app.Get("/", indexHandler.Handle)
app.Get("/lists/:list/", listHandler.Handle)
// Editor
app.Get("/editor/auth/", loginHandler.HandleGet)
app.Post("/editor/auth/", loginHandler.HandlePost)
2023-07-06 20:16:52 +00:00
app.Get("/editor/", editorListHandler.Handle)
app.Get("/editor/:editor/", editorHandler.HandleGet)
app.Post("/editor/:editor/", editorHandler.HandlePost)
2023-06-25 19:32:36 +00:00
// Media
app.Get("/media/*filepath", mediaHandler.Handle)
// RSS
app.Get("/index.xml", rssHandler.Handle)
// Posts
app.Get("/posts/:post/", entryHandler.Handle)
app.Get("/posts/:post/media/*filepath", mediaHandler.Handle)
// Webmention
// app.Post("/webmention/", userWebmentionHandler(repo))
// Micropub
// app.Post("/micropub/", userMicropubHandler(repo))
// IndieAuth
// app.Get("/auth/", userAuthHandler(repo))
// app.Post("/auth/", userAuthProfileHandler(repo))
// app.Post("/auth/verify/", userAuthVerifyHandler(repo))
// app.Post("/auth/token/", userAuthTokenHandler(repo))
// app.Get("/.well-known/oauth-authorization-server", userAuthMetadataHandler(repo))
// app.NotFound = http.HandlerFunc(notFoundHandler(repo))
2023-07-07 19:04:25 +00:00
return &WebApp{FiberApp: app, EntryService: entryService, Registry: typeRegistry}
2023-06-25 19:32:36 +00:00
}
func (w *WebApp) Run() {
2023-07-06 20:16:52 +00:00
w.FiberApp.Listen(":3000")
2023-06-25 19:32:36 +00:00
}