fix: restructure handler yet again #181

This commit is contained in:
2024-09-18 21:49:49 +02:00
parent 2f7081c0fe
commit a41265be98
4 changed files with 39 additions and 10 deletions

View File

@@ -16,11 +16,17 @@ func GetHandler(db *sql.DB) http.Handler {
// Serve static files (CSS, JS and images)
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
handleWorkout(db, router)
router.Handle("/auth/", authUi(db))
router.Handle("/api/auth/", authApi(db))
handleAuth(db, router)
router.Handle("/workout", auth(db, workoutUi(db)))
router.Handle("/api/workout", auth(db, workoutApi(db)))
// Needed a second time with trailing slash, otherwise either /api/workout or /api/workout/{id} does not match
router.Handle("/api/workout/", auth(db, workoutApi(db)))
return middleware.Logging(middleware.EnableCors(router))
return middleware.Logging(
middleware.EnableCors(
router))
}
func auth(db *sql.DB, h http.Handler) http.Handler {