mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
1.6 KiB
1.6 KiB
Task: Write an Express Route Registration Module with Correct Middleware Ordering
Context
The codeflash-internal cf-api is an Express server where route registration order is critical. Webhook routes must be registered before the JSON body parser because they need raw body access for signature verification. Protected routes require API key authentication via middleware.
You are adding a new set of routes for a "deployment" feature and need to integrate them into the existing route registration order.
Task
-
Write a TypeScript route registration module
routes/index.tsthat demonstrates the correct ordering:- Phase 1: Webhook routes (before body parser) -- include GitHub and Stripe webhook handlers
- Phase 2: Body parser with
express.json({ limit: JSON_BODY_LIMIT }) - Phase 3: Public routes (no auth)
- Phase 4: Protected routes with
checkForValidAPIKeymiddleware
-
Write a new
deployment.routes.tsmodule that:- Has
POST /deploy/trigger-- triggers a deployment - Has
POST /deploy/status-- checks deployment status - Has
POST /deploy/rollback-- rolls back a deployment - All routes are protected (require API key)
- Uses
trackEndpointCallsmiddleware for PostHog tracking - Uses
trackUsagemiddleware for usage tracking
- Has
-
Explain in a code comment why the webhook routes must come before
express.json()and what would break if they didn't.
Expected Outputs
- A
routes/index.tsshowing the 4-phase registration with the new deployment routes in the correct phase - A
deployment.routes.tswith the three endpoints and proper middleware - A comment explaining the webhook ordering requirement