Files
sonr/pkg/gateway/routes.go
T

33 lines
959 B
Go
Raw Normal View History

2024-12-05 20:36:58 -05:00
// Package gateway provides the default routes for the Sonr hway.
package gateway
import (
"github.com/labstack/echo/v4"
2024-12-05 20:36:58 -05:00
"github.com/onsonr/sonr/pkg/common/response"
"github.com/onsonr/sonr/pkg/gateway/config"
"github.com/onsonr/sonr/pkg/gateway/handlers"
2024-12-05 20:36:58 -05:00
"github.com/onsonr/sonr/pkg/gateway/internal/database"
"github.com/onsonr/sonr/pkg/gateway/internal/session"
)
2024-12-06 21:31:20 -05:00
func RegisterRoutes(e *echo.Echo, env config.Env) error {
// Custom error handler for gateway
2024-12-05 20:36:58 -05:00
e.HTTPErrorHandler = response.RedirectOnError("http://localhost:3000")
2024-12-06 21:31:20 -05:00
// Initialize database
db, err := database.InitDB(env)
if err != nil {
return err
}
// Inject session middleware with database connection
e.Use(session.Middleware(db))
2024-12-05 20:36:58 -05:00
// Register routes
e.GET("/", handlers.HandleIndex)
e.GET("/register", handlers.HandleRegisterView(env))
e.POST("/register/start", handlers.HandleRegisterStart)
e.POST("/register/finish", handlers.HandleRegisterFinish)
2024-12-06 21:31:20 -05:00
return nil
}