package http import ( "backend/config" "backend/docs" httpHandlers "backend/internal/api/http/handlers" "backend/internal/api/http/middlewares" "backend/internal/app" "fmt" "log" "github.com/gofiber/adaptor/v2" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" httpSwagger "github.com/swaggo/http-swagger" ) func Run(cfg config.Server, app *app.AppContainer) { fiberApp := fiber.New() fiberApp.Use(cors.New()) // Serve static files (HTML, CSS, JS) fiberApp.Static("/", "./static") api := fiberApp.Group("/api") // register routes here registerPublicRoutes(api, app) docs.SwaggerInfo.Host = fmt.Sprintf("%s:%d", cfg.Host, cfg.Port) docs.SwaggerInfo.BasePath = "/api" docs.SwaggerInfo.Schemes = []string{"http", "https"} api.Get("/swagger/*", adaptor.HTTPHandler(httpSwagger.Handler())) api.Get("/hello", middlewares.JWTAuthMiddleware([]byte("Secret")), func(c *fiber.Ctx) error { return c.SendString("Hello, World!") }) log.Printf("Server starting on %s:%d", cfg.Host, cfg.Port) log.Fatal(fiberApp.Listen(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port))) } func registerPublicRoutes(router fiber.Router, app *app.AppContainer) { authgroup := router.Group("/auth") authService := app.AuthService() authHandler := httpHandlers.NewAuthHandler(&authService) // Register auth routes authgroup.Post("/challenge", authHandler.GenerateChallenge) authgroup.Post("/authenticate", authHandler.Authenticate) authgroup.Post("/otp", authHandler.SendOTP) authgroup.Post("/verify", authHandler.VerifyOTP) // add JWT middleware for KYC authgroup.Post("/kyc", middlewares.JWTAuthMiddleware([]byte("Secret")), authHandler.VerifyKYC) }