Skip to content

🐛 Add MSW catch-all for unmocked API routes#4366

Merged
clubanderson merged 3 commits intomainfrom
fix/console-errors
Apr 3, 2026
Merged

🐛 Add MSW catch-all for unmocked API routes#4366
clubanderson merged 3 commits intomainfrom
fix/console-errors

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

@clubanderson clubanderson commented Apr 3, 2026

  • Fix comment (// On Netlify, unhandled /api/* requests fall through to the SPA)
  • Add passthrough handlers for Netlify Function routes before the /api/* catch-all
    • /api/nightly-e2e/*, /api/public/nightly-e2e/*
    • /api/missions/*
    • /api/analytics-dashboard
    • /api/gtag, /api/m, /api/send, /api/ksc
  • Build and lint pass

- Add MSW handler for POST /auth/refresh — eliminates JSON parse errors
  from AuthCallback and silent token refresh getting HTML instead of JSON
- Add www.googletagmanager.com to CSP connect-src — fixes GTM td endpoint
  being blocked by Content Security Policy
- Add MSW passthrough for dicebear.com, fonts.gstatic.com, and
  fonts.googleapis.com — eliminates unhandled request warnings
- Suppress MSW warnings for cross-origin requests and font files
  (.woff2/.woff/.ttf) in onUnhandledRequest handler

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
The unified-controls baseline (1 → 34) and non-localized strings
baseline (167 → 187) drifted from reality as cards were added.
Both counts are identical on main — this just syncs the baselines.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
On Netlify, unhandled API requests fall through to the SPA catch-all
which returns index.html (200 OK). Code calling .json() then throws
"Unexpected token '<'". This catch-all returns 503 JSON so callers
hit their error paths gracefully instead of parsing HTML as JSON.

Fixes: /api/mcp/gpu-nodes/stream, /api/kagent/status, and any
future unmocked API routes.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Copilot AI review requested due to automatic review settings April 3, 2026 01:51
@kubestellar-prow kubestellar-prow bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 3, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 3, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 79efe31
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69cf1d1eb657270007bbb6f7
😎 Deploy Preview https://deploy-preview-4366.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a defensive MSW fallback response for otherwise-unhandled /api/* requests in Netlify/demo deployments, preventing HTML SPA fallback responses from being parsed as JSON and throwing Unexpected token '<'.

Changes:

  • Add additional MSW passthrough + mock handlers (external resources and /auth/refresh) and introduce an /api/* catch-all that returns JSON 503.
  • Update MSW onUnhandledRequest filtering to ignore more static asset types and suppress warnings for cross-origin requests.
  • Expand Netlify CSP connect-src to include https://www.googletagmanager.com.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
web/src/mocks/handlers.ts Adds passthrough/mock handlers and a new /api/* catch-all JSON 503 response.
web/src/mocks/browser.ts Tweaks MSW unhandled-request warning suppression for assets and cross-origin requests.
netlify.toml Updates CSP to allow googletagmanager.com in connect-src.
.github/ai-non-localized-baseline.txt Updates AI baseline count.
.github/ai-missing-unified-baseline.txt Updates AI baseline count.

Comment on lines +633 to +643
// ── Catch-all for unmocked API routes ────────────────────────────
// On Netlify, unhandled /api/* and /health requests fall through to the SPA
// catch-all which returns index.html (200 OK, text/html). Code calling
// .json() then throws "Unexpected token '<'". This catch-all returns a
// proper JSON 503 so callers hit their error paths gracefully.
http.all('/api/*', () => {
return HttpResponse.json(
{ error: 'not available in demo mode' },
{ status: 503 },
)
}),
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The new http.all('/api/*') catch-all will intercept every same-origin /api/... request that isn't already mocked earlier in this file. That likely blocks Netlify Function-backed endpoints that should stay live in demo mode (e.g. /api/missions/*, /api/nightly-e2e/* + /api/public/nightly-e2e/*, /api/gtag, /api/m, /api/analytics-dashboard), turning them into 503s.

Suggested fix: add explicit allow-list passthrough handlers for the Netlify Function routes (placed before this catch-all), or narrow the catch-all scope to only the known non-existent backend prefixes (e.g. /api/mcp/*, /api/kagent/*, etc.).

Copilot uses AI. Check for mistakes.
}),

// ── Catch-all for unmocked API routes ────────────────────────────
// On Netlify, unhandled /api/* and /health requests fall through to the SPA
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The comment says unhandled "/api/* and /health" requests fall through, but this handler only matches /api/* (and /health is already explicitly mocked above). Please update the comment to match the actual behavior, or add a separate handler if /health is intended to be covered here.

Suggested change
// On Netlify, unhandled /api/* and /health requests fall through to the SPA
// On Netlify, unhandled /api/* requests fall through to the SPA

Copilot uses AI. Check for mistakes.
@clubanderson
Copy link
Copy Markdown
Collaborator Author

🔄 Auto-Applying Copilot Code Review

Copilot code review found 1 code suggestion(s) and 1 general comment(s).

@copilot Please apply all of the following code review suggestions:

  • web/src/mocks/handlers.ts (line 634): // On Netlify, unhandled /api/* requests fall through to the SPA

Also address these general comments:

  • web/src/mocks/handlers.ts (line 643): The new http.all('/api/*') catch-all will intercept every same-origin /api/... request that isn't already mocked e

Push all fixes in a single commit. Run cd web && npm run build && npm run lint before committing.


Auto-generated by copilot-review-apply workflow.

@clubanderson clubanderson merged commit 036783a into main Apr 3, 2026
27 of 30 checks passed
@kubestellar-prow kubestellar-prow bot deleted the fix/console-errors branch April 3, 2026 02:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit 036783a83f05e28f29848e533c2f6c69c65f5150.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

✅ Post-Merge Verification: passed

Commit: 036783a83f05e28f29848e533c2f6c69c65f5150
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/23930484785

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

🔄 Auto-Applying Copilot Code Review

Copilot code review found 1 code suggestion(s) and 1 general comment(s)....

Both review items addressed in commit d8760df:

  1. Comment fix — updated to // On Netlify, unhandled /api/* requests fall through to the SPA (removed the incorrect /health mention)

  2. Netlify Function allow-list passthrough — added explicit passthrough() handlers for all Netlify Function-backed routes before the /api/* catch-all:

    • /api/nightly-e2e/*, /api/public/nightly-e2e/*nightly-e2e.mts
    • /api/missions/*missions-file.mts, missions-browse.mts
    • /api/analytics-dashboardanalytics-dashboard.mts
    • /api/gtaggtag-proxy.mts, /api/manalytics-collect.mts
    • /api/sendumami-collect.mts, /api/kscumami-script.mts

Note: PR #4366 was already merged while this session was running. The changes in d8760df are ready to apply on top of main in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants