Added some rad new helpers, comments, and cleaned up the route group definitions!
This commit is contained in:
parent
b1e382420a
commit
96b766f47b
2 changed files with 36 additions and 22 deletions
|
@ -74,6 +74,7 @@ func SaveUser(dbPool *pgxpool.Pool, user *User) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AuthenticatedMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
func AuthenticatedMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
isSignedIn := IsSignedIn(c)
|
isSignedIn := IsSignedIn(c)
|
||||||
|
|
57
main.go
57
main.go
|
@ -51,13 +51,20 @@ func main() {
|
||||||
log.Fatalf("Failed to initialize schema: %v", err)
|
log.Fatalf("Failed to initialize schema: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Echo router
|
// Initialize Echo router and route groups
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
publicPageRoute := e.Group("")
|
||||||
|
protectedPageRoute := e.Group("", lib.AuthenticatedPageMiddleware)
|
||||||
|
publicApiRoute := e.Group("/api")
|
||||||
|
protectedApiRoute := e.Group("/api", lib.AuthenticatedEndpointMiddleware)
|
||||||
|
webhookGroup := e.Group("/webhook")
|
||||||
|
|
||||||
// Initialize the session store
|
// Initialize the session store
|
||||||
e.Use(lib.InitSessionMiddleware())
|
e.Use(lib.InitSessionMiddleware())
|
||||||
|
|
||||||
// Middleware
|
// ------------------------------
|
||||||
|
// Middleware:
|
||||||
|
// ------------------------------
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Pre(middleware.RemoveTrailingSlash())
|
e.Pre(middleware.RemoveTrailingSlash())
|
||||||
|
@ -68,35 +75,41 @@ func main() {
|
||||||
}))
|
}))
|
||||||
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(50)))
|
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(50)))
|
||||||
|
|
||||||
// Static server
|
// ------------------------------
|
||||||
|
// Static Server:
|
||||||
|
// ------------------------------
|
||||||
fs := http.FS(PublicFS)
|
fs := http.FS(PublicFS)
|
||||||
e.GET("/public/*", echo.WrapHandler(http.FileServer(fs)))
|
e.GET("/public/*", echo.WrapHandler(http.FileServer(fs)))
|
||||||
|
|
||||||
// Page routes
|
// ------------------------------
|
||||||
e.GET("/", pages.Home)
|
// Page Routes:
|
||||||
e.GET("/signin", pages.SignIn)
|
// ------------------------------
|
||||||
e.GET("/register", pages.Register)
|
publicPageRoute.GET("/", pages.Home)
|
||||||
e.GET("/dashboard", pages.Dashboard, lib.AuthenticatedMiddleware)
|
publicPageRoute.GET("/signin", pages.SignIn)
|
||||||
e.GET("/room/:id", pages.Room, lib.AuthenticatedMiddleware)
|
publicPageRoute.GET("/register", pages.Register)
|
||||||
|
protectedPageRoute.GET("/dashboard", pages.Dashboard)
|
||||||
|
protectedPageRoute.GET("/room/:id", pages.Room)
|
||||||
|
|
||||||
|
// ------------------------------
|
||||||
// API Routes:
|
// API Routes:
|
||||||
apiGroup := e.Group("/api")
|
// ------------------------------
|
||||||
apiGroup.GET("/ping", api.Ping)
|
// Generic API routes (public)
|
||||||
|
publicApiRoute.GET("/ping", api.Ping)
|
||||||
apiGroup.GET("/sse", func(c echo.Context) error {
|
publicApiRoute.GET("/sse", func(c echo.Context) error {
|
||||||
return api.SSE(c)
|
return api.SSE(c)
|
||||||
})
|
})
|
||||||
// Public routes
|
|
||||||
apiGroup.POST("/register", api.RegisterUserHandler)
|
// Auth routes (public)
|
||||||
apiGroup.POST("/signin", api.SignInUserHandler)
|
publicApiRoute.POST("/register", api.RegisterUserHandler)
|
||||||
apiGroup.POST("/signout", api.SignOutUserHandler)
|
publicApiRoute.POST("/signin", api.SignInUserHandler)
|
||||||
// Rooms routes
|
publicApiRoute.POST("/signout", api.SignOutUserHandler)
|
||||||
apiGroup.POST("/room", api.CreateRoomHandler)
|
|
||||||
apiGroup.GET("/room", api.GetAllRoomsHandler)
|
// Rooms routes (protected)
|
||||||
apiGroup.DELETE("/room/:id", api.DeleteRoomHandler)
|
protectedApiRoute.POST("/room", api.CreateRoomHandler)
|
||||||
|
protectedApiRoute.GET("/room", api.GetAllRoomsHandler)
|
||||||
|
protectedApiRoute.DELETE("/room/:id", api.DeleteRoomHandler)
|
||||||
|
|
||||||
// Webhook Routes:
|
// Webhook Routes:
|
||||||
webhookGroup := e.Group("/webhook")
|
|
||||||
webhookGroup.POST("/clerk", webhooks.ClerkWebhookHandler)
|
webhookGroup.POST("/clerk", webhooks.ClerkWebhookHandler)
|
||||||
|
|
||||||
// Parse command-line arguments for IP and port
|
// Parse command-line arguments for IP and port
|
||||||
|
|
Loading…
Add table
Reference in a new issue