Skip to content

Commit

Permalink
zess: move api to /api
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Aug 16, 2024
1 parent efcf748 commit 1d16733
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion vingo/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 14 additions & 5 deletions vingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ 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)

api.Post("/scans", handlers.ScanRegister)

api.Get("/recent_scans", handlers.PublicRecentScans)

// Protected routes
authed := api.Group("", handlers.IsLoggedIn)
{
authed.Post("/logout", handlers.Logout)
Expand All @@ -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)
Expand 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() {
Expand Down
2 changes: 1 addition & 1 deletion vinvoor/dev.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_BACKEND_URL="http://localhost:4000"
VITE_BACKEND_URL="http://localhost:4000/api"

VITE_DEFAULT_THEME_MODE="light"
2 changes: 1 addition & 1 deletion vinvoor/production.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_BACKEND_URL="http://localhost:4000"
VITE_BACKEND_URL="http://localhost:4000/api"

VITE_DEFAULT_THEME_MODE="light"

0 comments on commit 1d16733

Please sign in to comment.