Skip to content

fix(next): proxy agent server same-origin to avoid App Router CORS block - #17

Merged
Seungwoo321 merged 3 commits into
mainfrom
develop
Jun 27, 2026
Merged

fix(next): proxy agent server same-origin to avoid App Router CORS block#17
Seungwoo321 merged 3 commits into
mainfrom
develop

Conversation

@Seungwoo321

Copy link
Copy Markdown
Owner

Problem

The agent server is loopback-only with no Access-Control-* surface (by design, same as the Vite path). The Next adapter injected the raw http://127.0.0.1:<port> agent URL as the widget base URL, so the in-page widget fetched /v1/agent/commands / /v1/agent/stream cross-origin from the dev page (localhost:<port>). The browser blocked it (No 'Access-Control-Allow-Origin' header) — the widget mounted but could never talk to its backend.

Verified on Next 16 + Turbopack against wireweave/dashboard: widget host mounts, but DevTools shows the CORS error on /v1/agent/commands.

Fix

withAgentDevtools now mirrors the Vite plugin's proxy:

  • Injects a same-origin base path (/__agent_devtools) as the widget base URL instead of the raw agent URL.
  • Installs a Next rewrites() rule forwarding /__agent_devtools/:path* → the agent server, composed ahead of any existing user rewrites (beforeFiles).
  • No baseUrl supplied → no rewrite, clean no-op.

Browser requests stay same-origin (no CORS); the agent server keeps its loopback-only, no-CORS posture.

Tests

packages/next typecheck / build green; vitest 30 passed (added: proxy-path base URL injection, rewrite rule shape, composition ahead of user rewrites, no-baseUrl no-op).

Changeset: @agent-devtools/next patch.

🤖 Generated with Claude Code

github-actions Bot and others added 2 commits June 27, 2026 08:35
The agent server is loopback-only with no Access-Control-* surface. The Next
adapter injected the raw 127.0.0.1:<port> agent URL as the widget base URL, so
the in-page widget fetched /v1/agent/* cross-origin from the dev page and the
browser blocked it (no Access-Control-Allow-Origin). The widget mounted but
could not reach its backend.

withAgentDevtools now mirrors the Vite plugin's proxy: it injects a same-origin
base path (/__agent_devtools) and installs a Next rewrites() rule forwarding
/__agent_devtools/:path* to the agent server, composing ahead of any existing
user rewrites. No baseUrl -> no rewrite (clean no-op).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-devtools-docs Ready Ready Preview, Comment Jun 27, 2026 8:58am

Request Review

@Seungwoo321
Seungwoo321 merged commit c1b704d into main Jun 27, 2026
2 checks passed
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