Skip to content

fix(deploy): route /api/** to the engine via explicit rewrite (HT-43) - #51

Merged
zaridan merged 2 commits into
mainfrom
fix/ht-43-api-catchall-routing
Jul 17, 2026
Merged

fix(deploy): route /api/** to the engine via explicit rewrite (HT-43)#51
zaridan merged 2 commits into
mainfrom
fix/ht-43-api-catchall-routing

Conversation

@zaridan

@zaridan zaridan commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Production requests to any multi-segment API path (/api/v1/conversations, cron endpoints) returned Vercel's platform 404. Root cause, verified by inspecting the generated .vercel/output/config.json: the CLI's zero-config router turns the api/[...path].ts catch-all into a single-segment route (^/api/([^/]+)$, param literally named ...path), so anything deeper never reaches the function.

Fix: rename to api/index.ts + an explicit rewrites rule (/api/:path*/api). A rewrite picks the serving function but preserves the original request.url, which is all the handler uses (the engine's own router does path dispatch). Doc comment updated to record why the catch-all filename is not used.

Verification (live, production)

  • Before: all API paths → Vercel NOT_FOUND page.
  • After (this branch deployed to prod, which was already broken — rollback path was redeploying main): all paths reach the engine — responses are the engine's own error envelope, and runtime logs show loadConfig's fail-fast naming exactly the five not-yet-provisioned Google env vars (GMAIL_OAUTH_CLIENT_ID/SECRET, GMAIL_PUBSUB_TOPIC/SUBSCRIPTION, GMAIL_PUSH_SERVICE_ACCOUNT). Function bundling, routing, env loading, and the 500 envelope all confirmed working.

This PR makes main match what production is running.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Enabled API-path routing so requests to /api/* are forwarded to the central API handler.
  • Documentation

    • Clarified how catch-all API routing and path dispatch are handled in the deployment environment, including the implications of rewrite behavior.

Vercel's zero-config route generation (CLI 55/56) emits a single-segment
route (^/api/([^/]+)$) for the bracketed [...path].ts catch-all, 404ing
every multi-segment /api/v1/... path in production. Rename the function
to api/index.ts and route /api/:path* to it with an explicit vercel.json
rewrite — a rewrite selects the serving function but leaves request.url
as the original client path, which is all the engine's router needs.

Verified live on production: /api/v1/conversations now reaches the
engine (its own error envelope + loadConfig fail-fast naming the five
not-yet-provisioned Google env vars), where before it hit Vercel's
platform 404.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 62afed91-ffd8-4ca1-a9c6-f4cf06fa6b4b

📥 Commits

Reviewing files that changed from the base of the PR and between ad8ca4f and fca1e44.

📒 Files selected for processing (1)
  • src/composition/root.ts

📝 Walkthrough

Walkthrough

Vercel now rewrites /api/:path* requests to /api. Related documentation explains URL preservation, internal path dispatch, and the memoized handler’s api/index.ts entry point.

Changes

API routing

Layer / File(s) Summary
Vercel API rewrite and routing documentation
vercel.json, api/index.ts, src/composition/root.ts
Adds an /api/:path* rewrite to /api and updates documentation describing nested API dispatch and the memoized Vercel handler entry point.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the deployment routing fix and the explicit rewrite that sends /api/** requests to the engine.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ht-43-api-catchall-routing

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/index.ts`:
- Around line 16-24: Update the stale Vercel entry-point documentation in the
composition root comment to reference api/index.ts instead of api/[...path].ts.
Preserve the surrounding routing explanation and do not change runtime behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5aaf0987-10a9-417b-9d42-5c75f3b15bcc

📥 Commits

Reviewing files that changed from the base of the PR and between 91c61c4 and ad8ca4f.

📒 Files selected for processing (2)
  • api/index.ts
  • vercel.json

Comment thread api/index.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zaridan
zaridan merged commit e5c9ccd into main Jul 17, 2026
5 checks passed
@zaridan
zaridan deleted the fix/ht-43-api-catchall-routing branch August 2, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant