fix: route openapi playground's ?url= proxy calls to the daemon#14
Merged
Conversation
The fumadocs-openapi Try It playground calls the proxy as /api/coven-proxy?url=<encoded-target>&cookie= with the target URL as a query parameter — a single endpoint, not a path prefix. The existing catch-all route at /api/coven-proxy/[...path]/route.ts requires at least one path segment, so the playground's request hit Next's /_not-found and the Try It panel rendered a 404 HTML dump instead of the daemon's JSON envelope. Adds a sibling route at /api/coven-proxy/route.ts that reads ?url=, strips the /api/coven-proxy prefix from the target's pathname, and forwards the remaining daemon path to the Unix socket. Extracts the dialing logic into lib/coven-proxy-dial.ts so both proxy shapes share one implementation: - /api/coven-proxy/[...path]/route.ts → status banner, curl tests - /api/coven-proxy/route.ts → fumadocs-openapi playground Both end up calling dialDaemon(targetPath, ...) on $COVEN_HOME/coven.sock with the same envelope-error contract (daemon_unreachable, invalid_request, internal_error). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Fixes fumadocs-openapi “Try It” requests that proxy via /api/coven-proxy?url=... by adding a sibling route handler and extracting shared Unix-socket dialing logic so both proxy shapes return consistent daemon responses/envelopes.
Changes:
- Added
/api/coven-proxyroute to handle the playground’s?url=proxy format and forward to the daemon. - Introduced
lib/coven-proxy-dial.tsto centralize socket-path resolution, request forwarding, anddaemon_unreachableerror envelopes. - Refactored the existing catch-all
/api/coven-proxy/[...path]route to delegate to the shared dialer.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/coven-proxy-dial.ts | New shared helper to dial the daemon over $COVEN_HOME/coven.sock and normalize errors into consistent envelopes. |
| app/api/coven-proxy/route.ts | New handler for fumadocs-openapi’s ?url= proxy requests; extracts daemon path and forwards via dialDaemon(). |
| app/api/coven-proxy/[...path]/route.ts | Simplified existing path-prefix proxy route by delegating socket logic to dialDaemon(). |
Comment on lines
+46
to
+54
| if (!targetUrl.pathname.startsWith(PROXY_PREFIX)) { | ||
| return envelope( | ||
| 'invalid_request', | ||
| `Target URL pathname must start with ${PROXY_PREFIX}: ${targetUrl.pathname}`, | ||
| { source: 'playground' }, | ||
| 400, | ||
| ); | ||
| } | ||
| const targetPath = targetUrl.pathname.slice(PROXY_PREFIX.length) + targetUrl.search; |
Comment on lines
+90
to
+103
| /** | ||
| * Dial the daemon's Unix socket with the given path/method/body and return | ||
| * a `Response` mirroring the daemon's reply. On connect failure or timeout, | ||
| * returns a 503 `daemon_unreachable` envelope. | ||
| * | ||
| * `targetPath` is the daemon-side path (e.g., `/api/v1/health`), NOT the | ||
| * docs-site bridge path. | ||
| */ | ||
| export async function dialDaemon( | ||
| targetPath: string, | ||
| method: string, | ||
| requestHeaders: Headers, | ||
| body: Buffer | undefined, | ||
| ): Promise<Response> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After #12 landed, the Try It panels on every endpoint page rendered a Next.js 404 HTML dump instead of the daemon's JSON response. Root cause: fumadocs-openapi's playground proxies via a single endpoint with the target URL as a query parameter —
— but #12 only shipped
app/api/coven-proxy/[...path]/route.ts, a catch-all that requires at least one path segment. The playground's request hit Next's/_not-found.Fix
app/api/coven-proxy/route.ts(new) — sibling route handling the?url=style. Validates the target URL is under/api/coven-proxy/, strips that prefix, and forwards the remaining daemon-side path to the Unix socket.lib/coven-proxy-dial.ts(new) — extracts the dialing logic (socket-path resolution,http.request({ socketPath })plumbing,daemon_unreachableenvelope onENOENT/ECONNREFUSED/ETIMEDOUT/EACCES,VERCEL=1hosted short-circuit) so both routes share one implementation.app/api/coven-proxy/[...path]/route.ts— refactored to delegate todialDaemon(). Status banner + curl tests continue to work unchanged.Both proxy shapes end up calling
dialDaemon(targetPath, method, headers, body)on$COVEN_HOME/coven.sockwith the same envelope-error contract.Test plan
npm run dev, start a daemon (coven daemon start), then:/docs/openapi/meta/get-healthand click Try It → real{"ok":true,"apiVersion":"coven.daemon.v1",...}response (not a 404 HTML dump)./docs/openapi/sessions/create-sessionwith a valid body launches a real session and returns the SessionRecord./docs/openapistill flips green when a daemon is running (path-prefix route unchanged).curl http://localhost:3000/api/coven-proxy/api/v1/health(path-prefix) returns the same payload ascurl 'http://localhost:3000/api/coven-proxy?url=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fcoven-proxy%2Fapi%2Fv1%2Fhealth&cookie='(playground style).daemon_unreachable503 envelope.VERCEL=1 npm run dev→ banner shows hosted panel; Try It returnsdetails.hosted: trueenvelope.🤖 Generated with Claude Code