mirror of
https://github.com/cf-sonr/motr.git
synced 2026-01-12 02:59:13 +00:00
refactor: centralize route definitions for radar and worker
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/sonr-io/motr/middleware/database"
|
||||
"github.com/sonr-io/motr/middleware/kvstore"
|
||||
"github.com/sonr-io/motr/middleware/marketapi"
|
||||
"github.com/sonr-io/motr/middleware/session"
|
||||
"github.com/sonr-io/motr/routes"
|
||||
"github.com/sonr-io/motr/middleware/sonrapi"
|
||||
"github.com/sonr-io/motr/middleware/webauthn"
|
||||
"github.com/syumai/workers"
|
||||
"github.com/syumai/workers/cloudflare/cron"
|
||||
|
||||
@@ -27,9 +27,15 @@ import (
|
||||
// Setup the HTTP handler
|
||||
func loadHandler() http.Handler {
|
||||
e := echo.New()
|
||||
e.Use(session.Middleware(), database.Middleware(), kvstore.Middleware(), marketapi.Middleware())
|
||||
routes.SetupViews(e)
|
||||
routes.SetupPartials(e)
|
||||
e.Use(
|
||||
session.Middleware(),
|
||||
database.Middleware(),
|
||||
kvstore.Middleware(),
|
||||
sonrapi.Middleware(),
|
||||
webauthn.Middleware(),
|
||||
)
|
||||
setupViews(e)
|
||||
setupPartials(e)
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -55,8 +61,8 @@ func main() {
|
||||
t := loadTask()
|
||||
|
||||
// Configure Worker
|
||||
workers.ServeNonBlock(e)
|
||||
cron.ScheduleTaskNonBlock(t)
|
||||
workers.ServeNonBlock(e)
|
||||
workers.Ready()
|
||||
|
||||
// Block until handler/task is done
|
||||
|
||||
32
cmd/radar/routes.go
Normal file
32
cmd/radar/routes.go
Normal file
@@ -0,0 +1,32 @@
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/sonr-io/motr/handlers"
|
||||
"github.com/sonr-io/motr/internal/ui/home"
|
||||
"github.com/sonr-io/motr/internal/ui/login"
|
||||
"github.com/sonr-io/motr/internal/ui/register"
|
||||
"github.com/sonr-io/motr/middleware/render"
|
||||
)
|
||||
|
||||
// ╭────────────────────────────────────────────────╮
|
||||
// │ HTTP Routes │
|
||||
// ╰────────────────────────────────────────────────╯
|
||||
|
||||
func setupViews(e *echo.Echo) {
|
||||
e.GET("/", render.Page(home.HomeView()))
|
||||
e.GET("/login", render.Page(login.LoginView()))
|
||||
e.GET("/register", render.Page(register.RegisterView()))
|
||||
}
|
||||
|
||||
func setupPartials(e *echo.Echo) {
|
||||
e.POST("/login/:handle/check", handlers.HandleLoginCheck)
|
||||
e.POST("/login/:handle/finish", handlers.HandleLoginFinish)
|
||||
e.POST("/register/:handle", handlers.HandleRegisterStart)
|
||||
e.POST("/register/:handle/check", handlers.HandleRegisterCheck)
|
||||
e.POST("/register/:handle/finish", handlers.HandleRegisterFinish)
|
||||
e.POST("/status", handlers.HandleStatusCheck)
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/sonr-io/motr/middleware/session"
|
||||
"github.com/sonr-io/motr/middleware/sonrapi"
|
||||
"github.com/sonr-io/motr/middleware/webauthn"
|
||||
"github.com/sonr-io/motr/routes"
|
||||
"github.com/syumai/workers"
|
||||
"github.com/syumai/workers/cloudflare/cron"
|
||||
|
||||
@@ -28,9 +27,15 @@ import (
|
||||
// Setup the HTTP handler
|
||||
func loadHandler() http.Handler {
|
||||
e := echo.New()
|
||||
e.Use(session.Middleware(), database.Middleware(), kvstore.Middleware(), sonrapi.Middleware(), webauthn.Middleware())
|
||||
routes.SetupViews(e)
|
||||
routes.SetupPartials(e)
|
||||
e.Use(
|
||||
session.Middleware(),
|
||||
database.Middleware(),
|
||||
kvstore.Middleware(),
|
||||
sonrapi.Middleware(),
|
||||
webauthn.Middleware(),
|
||||
)
|
||||
setupViews(e)
|
||||
setupPartials(e)
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -56,8 +61,8 @@ func main() {
|
||||
t := loadTask()
|
||||
|
||||
// Configure Worker
|
||||
workers.ServeNonBlock(e)
|
||||
cron.ScheduleTaskNonBlock(t)
|
||||
workers.ServeNonBlock(e)
|
||||
workers.Ready()
|
||||
|
||||
// Block until handler/task is done
|
||||
|
||||
32
cmd/worker/routes.go
Normal file
32
cmd/worker/routes.go
Normal file
@@ -0,0 +1,32 @@
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/sonr-io/motr/handlers"
|
||||
"github.com/sonr-io/motr/internal/ui/home"
|
||||
"github.com/sonr-io/motr/internal/ui/login"
|
||||
"github.com/sonr-io/motr/internal/ui/register"
|
||||
"github.com/sonr-io/motr/middleware/render"
|
||||
)
|
||||
|
||||
// ╭────────────────────────────────────────────────╮
|
||||
// │ HTTP Routes │
|
||||
// ╰────────────────────────────────────────────────╯
|
||||
|
||||
func setupViews(e *echo.Echo) {
|
||||
e.GET("/", render.Page(home.HomeView()))
|
||||
e.GET("/login", render.Page(login.LoginView()))
|
||||
e.GET("/register", render.Page(register.RegisterView()))
|
||||
}
|
||||
|
||||
func setupPartials(e *echo.Echo) {
|
||||
e.POST("/login/:handle/check", handlers.HandleLoginCheck)
|
||||
e.POST("/login/:handle/finish", handlers.HandleLoginFinish)
|
||||
e.POST("/register/:handle", handlers.HandleRegisterStart)
|
||||
e.POST("/register/:handle/check", handlers.HandleRegisterCheck)
|
||||
e.POST("/register/:handle/finish", handlers.HandleRegisterFinish)
|
||||
e.POST("/status", handlers.HandleStatusCheck)
|
||||
}
|
||||
Reference in New Issue
Block a user