This backend now applies a route-level CORS helper from src/lib/backend/cors.ts.
Each API method is classified as either:
public: browser clients may call the route cross-origin. By default these responses sendAccess-Control-Allow-Origin: *and never opt into credentials.first-party: only trusted Commitlabs web origins may call the route from a browser. These responses echo the approved origin and sendAccess-Control-Allow-Credentials: true.
The helper also answers OPTIONS preflight requests and rejects disallowed
origins with 403.
Set these environment variables for deployment:
COMMITLABS_FIRST_PARTY_ORIGINSComma-separated list of trusted application origins allowed to call first-party routes from the browser. Example:https://app.commitlabs.com,https://staging.commitlabs.comCOMMITLABS_PUBLIC_API_ORIGINSComma-separated list of allowed origins for public browser routes, or*. Default:*
Development defaults always include:
http://localhost:3000http://127.0.0.1:3000
The helper also folds in deployed app URLs from APP_URL,
NEXT_PUBLIC_APP_URL, SITE_URL, NEXT_PUBLIC_SITE_URL,
VERCEL_PROJECT_PRODUCTION_URL, and VERCEL_URL when they are present.
- Wildcard origin is never combined with credentials.
- First-party routes reject cross-origin browser requests unless the
Originheader matches the trusted allowlist. - Public routes stay credential-free unless they are explicitly reconfigured.
- Preflight requests validate both the requested method and the requested
headers before returning
204.
Public browser routes:
GET /api/healthGET /api/metricsGET /api/readyGET /api/marketplaceGET /api/marketplace/listingsGET /api/attestations
First-party browser routes:
- All
/api/auth/*routes POST /api/login- All
/api/commitments/*routes GET /api/analytics/userPOST /api/attestationsPOST /api/marketplacePOST /api/marketplace/listingsDELETE /api/marketplace/listings/[id]POST /api/seed
Each route now exposes only its implemented methods plus OPTIONS. Example:
GET /api/healthresponds withAccess-Control-Allow-Methods: GET, OPTIONSGET|POST /api/marketplace/listingsresponds withAccess-Control-Allow-Methods: GET, POST, OPTIONSDELETE /api/marketplace/listings/[id]responds withAccess-Control-Allow-Methods: DELETE, OPTIONS