diff --git a/vingo/dev.env b/vingo/dev.env index d96f2f3..474eefb 100644 --- a/vingo/dev.env +++ b/vingo/dev.env @@ -2,7 +2,7 @@ CORS_ALLOW_ORIGINS="http://localhost:5173" DEVELOPMENT=true ZAUTH_URL="https://zauth.zeus.gent" -ZAUTH_CALLBACK_PATH="/auth/callback" +ZAUTH_CALLBACK_PATH="/api/auth/callback" ZAUTH_CLIENT_ID="tomtest" ZAUTH_CLIENT_SECRET="blargh" ZAUTH_REDIRECT_URI="http://localhost:5173" diff --git a/vingo/main.go b/vingo/main.go index 026aada..4de4975 100644 --- a/vingo/main.go +++ b/vingo/main.go @@ -29,20 +29,22 @@ func main() { db := database.Get() defer db.Close() - api := fiber.New(fiber.Config{}) + app := fiber.New(fiber.Config{}) if development { - api.Use(cors.New(cors.Config{ + app.Use(cors.New(cors.Config{ AllowOrigins: corsAllowOrigins, AllowHeaders: "Origin, Content-Type, Accept, Access-Control-Allow-Origin", AllowCredentials: true, })) } else { - api.Static("/", "./public") + app.Static("/", "./public") } - // Public routes + api := app.Group("/api") + { + // Public routes api.Post("/login", handlers.Login) api.Get("/auth/callback", handlers.Callback) @@ -50,6 +52,7 @@ func main() { api.Get("/recent_scans", handlers.PublicRecentScans) + // Protected routes authed := api.Group("", handlers.IsLoggedIn) { authed.Post("/logout", handlers.Logout) @@ -65,6 +68,7 @@ func main() { authed.Get("/settings", handlers.Settings{}.Get) authed.Patch("/settings", handlers.Settings{}.Update) + // Admin routes admin := authed.Group("/admin", handlers.IsAdmin) { admin.Get("/days", handlers.Days{}.All) @@ -74,7 +78,12 @@ func main() { } } - log.Println(api.Listen(":4000")) + // Catch-all route leading to the frontend + app.Get("*", func(c *fiber.Ctx) error { + return c.SendFile("./public/index.html") + }) + + log.Println(app.Listen(":4000")) } func setupFromEnv() { diff --git a/vinvoor/dev.env b/vinvoor/dev.env index 317c45a..fad4423 100644 --- a/vinvoor/dev.env +++ b/vinvoor/dev.env @@ -1,3 +1,3 @@ -VITE_BACKEND_URL="http://localhost:4000" +VITE_BACKEND_URL="http://localhost:4000/api" VITE_DEFAULT_THEME_MODE="light" diff --git a/vinvoor/production.env b/vinvoor/production.env index 317c45a..fad4423 100644 --- a/vinvoor/production.env +++ b/vinvoor/production.env @@ -1,3 +1,3 @@ -VITE_BACKEND_URL="http://localhost:4000" +VITE_BACKEND_URL="http://localhost:4000/api" VITE_DEFAULT_THEME_MODE="light"