Skip to content

docs: compound Vite API proxy source-module fix#1507

Merged
gsxdsm merged 1 commit into
mainfrom
docs/vite-api-source-modules-proxy
Jun 8, 2026
Merged

docs: compound Vite API proxy source-module fix#1507
gsxdsm merged 1 commit into
mainfrom
docs/vite-api-source-modules-proxy

Conversation

@gsxdsm

@gsxdsm gsxdsm commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Document the dashboard dev-server issue where Vite /api* source-module requests were proxied to the backend.
  • Capture the final proxy regex, verification checks, and prevention guidance for agent-browser / HMR debugging.

Verification

  • python3 plugins/fusion-plugin-compound-engineering/src/skills/ce-compound/scripts/validate-frontmatter.py docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md

Summary by CodeRabbit

  • Documentation
    • Added troubleshooting guide for Vite proxy configuration issues affecting dashboard development mode, with detailed symptoms, resolution steps, verification commands, and testing guidance.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added a new documentation article describing a Vite dev-server proxy misconfiguration in the dashboard where the /api proxy rule incorrectly forwarded source module requests to the backend. The doc covers observed symptoms, root cause analysis, the fix using regex with negative lookahead, verification steps, and prevention guidance.

Changes

Vite Proxy Integration Issue Documentation

Layer / File(s) Summary
Integration issue documentation with diagnosis and fix
docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md
New documentation article describing the Vite proxy misconfiguration where /api proxy rule misrouted source module requests (e.g., /api.ts, /api-node.ts, /api/legacy.ts) to the backend, observed symptoms in agent-browser showing a blank/broken dashboard, root cause explanation, the solution using a regex proxy key with negative lookahead in packages/dashboard/vite.config.ts, curl verification commands, regex behavior explanation, and prevention/testing recommendations with related issue links.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A proxy gone wrong made the dashboard feel sad,
Source modules astray made the agent quite mad,
A lookahead regex saved the day with a fix,
Now Vite serves its modules—no more API mix! 🐰✨

🚥 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 accurately describes the main change: documenting a Vite API proxy issue involving source modules. It is concise, specific, and directly matches the file added.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/vite-api-source-modules-proxy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a solution document capturing the root cause, failed approaches, final fix, and prevention guidance for the case where Vite's dev-server proxy was forwarding source-module requests (/api.ts, /api/legacy.ts, etc.) to the backend instead of Vite's module pipeline.

  • The documented regex ^/api(?!/.*\\.[jt]sx?(?:\\?|$))(/|$) matches the implementation in packages/dashboard/vite.config.ts exactly, and both related cross-links resolve to existing files.
  • Frontmatter is well-formed and the verification script is called out in the PR description; the Symptoms, Solution, and Prevention sections are clear and self-consistent.

Confidence Score: 4/5

Documentation-only change; the documented regex is a verbatim copy of the live vite.config.ts implementation, both related cross-links resolve, and the frontmatter passes validation.

The document is accurate and well-structured. The only gap is that the "Why This Works" section explains the negative lookahead in detail but does not mention the (/|$) suffix that handles top-level paths like /api.ts and /api-node.ts, creating a small blind spot for readers following just that explanation.

The new solution document is the only file changed; the regex explanation section is the one area worth a second read.

Important Files Changed

Filename Overview
docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md New solution document for the Vite /api* proxy misrouting issue; regex shown matches vite.config.ts exactly; related file links resolve; frontmatter is well-formed; "Why This Works" section omits the role of the (/

Sequence Diagram

sequenceDiagram
    participant Browser
    participant Vite as Vite Dev Server
    participant Backend as Backend API (port 4040)

    Note over Browser,Backend: /api/health → proxied (no source-module extension)
    Browser->>Vite: GET /api/health
    Vite->>Backend: proxy (regex matches)
    Backend-->>Browser: 200 JSON

    Note over Browser,Vite: /api/legacy.ts → served by Vite (lookahead fires)
    Browser->>Vite: GET /api/legacy.ts
    Vite-->>Browser: 200 JS module (regex does NOT match)

    Note over Browser,Vite: /api/legacy.ts?import → served by Vite (? after extension caught)
    Browser->>Vite: GET /api/legacy.ts?import
    Vite-->>Browser: 200 JS module (regex does NOT match)

    Note over Browser,Vite: /api.ts → served by Vite ((/|$) fails, . after /api)
    Browser->>Vite: GET /api.ts
    Vite-->>Browser: 200 JS module (regex does NOT match)
Loading

Reviews (1): Last reviewed commit: "docs: compound Vite API proxy source mod..." | Re-trigger Greptile

Comment on lines +89 to +94
The negative lookahead rejects source-module extensions before the proxy claims the request:

- `/api/health` matches the proxy and reaches the backend.
- `/api/legacy.ts` does not match the proxy and stays on Vite.
- `/api/legacy.ts?import` also stays on Vite because the source-extension check allows an optional query string.
- `.tsx`, `.js`, and `.jsx` are excluded too so future source modules do not rediscover the same failure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The "Why This Works" section attributes all protective behavior to the negative lookahead, but the (/|$) suffix at the end of the regex is actually what keeps /api.ts and /api-node.ts on Vite — the character immediately after /api in those URLs is . or -, not / or end-of-string, so the regex never reaches the lookahead. A reader might wonder how /api.ts (mentioned in Symptoms) is excluded if the only listed examples in this section are /api/... paths. Adding one explicit example makes the full regex behavior clear.

Suggested change
The negative lookahead rejects source-module extensions before the proxy claims the request:
- `/api/health` matches the proxy and reaches the backend.
- `/api/legacy.ts` does not match the proxy and stays on Vite.
- `/api/legacy.ts?import` also stays on Vite because the source-extension check allows an optional query string.
- `.tsx`, `.js`, and `.jsx` are excluded too so future source modules do not rediscover the same failure.
The negative lookahead rejects source-module extensions before the proxy claims the request, and the trailing `(/|$)` anchor ensures the regex only fires on real API path prefixes:
- `/api/health` matches the proxy and reaches the backend.
- `/api/legacy.ts` does not match the proxy and stays on Vite.
- `/api/legacy.ts?import` also stays on Vite because the source-extension check allows an optional query string.
- `/api.ts` and `/api-node.ts` stay on Vite because the character after `/api` is `.` or `-`, not `/` or end-of-string, so `(/|$)` fails before the lookahead is even evaluated.
- `.tsx`, `.js`, and `.jsx` are excluded too so future source modules do not rediscover the same failure.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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
`@docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md`:
- Around line 85-94: Update the explanation around the proxy regex (the
caret-anchored pattern with the negative lookahead) to explicitly state how it
treats top-level source-module filenames like "/api.ts" and "/api-node.ts" as
well as nested paths such as "/api/legacy.ts"; mention that the negative
lookahead excludes extensions (.ts, .tsx, .js, .jsx) immediately following the
"/api" prefix or directly after "/api" (so "/api.ts" and "/api-node.ts" are kept
by Vite), and if you changed the regex per the prior comment, update the wording
to reflect the corrected pattern behavior and examples.
🪄 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: daeaff7c-2eff-443f-baeb-c4ce718da59d

📥 Commits

Reviewing files that changed from the base of the PR and between 708c3c2 and ca96ba5.

📒 Files selected for processing (1)
  • docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md

Comment on lines +85 to +94
## Why This Works

Vite treats proxy keys beginning with `^` as regular expressions matched against the request URL. The dashboard has source modules whose served URLs begin with `/api`, while the backend API namespace also begins with `/api`; a prefix rule cannot distinguish them.

The negative lookahead rejects source-module extensions before the proxy claims the request:

- `/api/health` matches the proxy and reaches the backend.
- `/api/legacy.ts` does not match the proxy and stays on Vite.
- `/api/legacy.ts?import` also stays on Vite because the source-extension check allows an optional query string.
- `.tsx`, `.js`, and `.jsx` are excluded too so future source modules do not rediscover the same failure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Clarify the regex explanation for top-level source modules.

The explanation focuses on nested paths like /api/legacy.ts but doesn't explicitly address how the regex handles top-level files like /api.ts and /api-node.ts mentioned in the symptoms. If the regex needs adjustment (per the previous comment), this explanation should be updated to match the corrected pattern.

🤖 Prompt for 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.

In
`@docs/solutions/integration-issues/vite-api-source-modules-proxied-to-backend.md`
around lines 85 - 94, Update the explanation around the proxy regex (the
caret-anchored pattern with the negative lookahead) to explicitly state how it
treats top-level source-module filenames like "/api.ts" and "/api-node.ts" as
well as nested paths such as "/api/legacy.ts"; mention that the negative
lookahead excludes extensions (.ts, .tsx, .js, .jsx) immediately following the
"/api" prefix or directly after "/api" (so "/api.ts" and "/api-node.ts" are kept
by Vite), and if you changed the regex per the prior comment, update the wording
to reflect the corrected pattern behavior and examples.

@gsxdsm
gsxdsm merged commit e0ab3b5 into main Jun 8, 2026
6 checks passed
@gsxdsm
gsxdsm deleted the docs/vite-api-source-modules-proxy branch June 8, 2026 06:36
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