fix(middleware): restore plugin route map — /gateway returns 404#183
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR expands the middleware's plugin route mapping and introduces authentication-based redirects that redirect already-authenticated users away from login/register routes to the dashboard. It adds a plugin route mapping generation feature to the sync script and reorders the build pipeline to execute plugin registry sync before the Next.js build. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
bin/vercel-build.sh (1)
9-11: Step labels are now inconsistent across the script.This header changed to 6 steps, but earlier log lines still emit
[0/5]to[3/5]. Consider aligning all step counters to the same denominator for cleaner deploy logs.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bin/vercel-build.sh` around lines 9 - 11, The script header was updated to list 6 steps but status logs still use a "/5" denominator (e.g., messages matching the "[x/5]" pattern); update all progress log echoes in bin/vercel-build.sh to use the consistent "/6" denominator (or alternatively revert the header to 5 steps) so every status message (those emitting "[0/5]" through "[3/5]") matches the header; search for the literal "/5" progress strings in the script and change them to "/6" and adjust any incremented step numbers if needed to reflect the actual step sequence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web-next/src/middleware.ts`:
- Around line 4-27: Replace the hardcoded PLUGIN_ROUTE_MAP constant in
middleware.ts with the generated mapping by importing the generated
plugin-routes.json (e.g., import pluginRoutes from 'plugin-routes.json') and
assigning it to PLUGIN_ROUTE_MAP as a typed Record<string,string>; ensure you
cast/validate the imported JSON shape before use, keep a small fallback to the
existing inline map only if the generated JSON is missing (and log an error),
and remove the static entries so middleware always reads from the generated
mapping (referencing the PLUGIN_ROUTE_MAP symbol and the generated
plugin-routes.json filename).
- Around line 211-214: The auth-route check in middleware.ts is too permissive:
authRoutes.some(route => pathname.startsWith(route)) matches paths like
"/login-help"; change the predicate used where authRoutes and pathname are
compared so it only matches the exact route or the route followed by a slash
(e.g., pathname === route || pathname.startsWith(route + '/')) before performing
the redirect (the block that checks token and returns
NextResponse.redirect('/dashboard', request.url)). Ensure you update the
condition that references authRoutes and pathname.startsWith(route) accordingly.
In `@bin/sync-plugin-registry.ts`:
- Around line 340-347: The current loop over discovered plugins silently
overwrites routeMap entries when multiple plugins share the same base route (in
the block using discovered, toCamelCase, routes, baseRoute, routesWithOwnPage,
and routeMap), so change the logic to detect collisions: before assigning
routeMap[baseRoute] = camelName, check if routeMap already has baseRoute and if
so either throw a descriptive error (fail fast) or log a warning and skip/retain
the existing mapping (keep-first); implement the chosen behavior consistently
and include context (baseRoute, existing owner, new camelName) in the
error/warning message to make debugging straightforward.
---
Nitpick comments:
In `@bin/vercel-build.sh`:
- Around line 9-11: The script header was updated to list 6 steps but status
logs still use a "/5" denominator (e.g., messages matching the "[x/5]" pattern);
update all progress log echoes in bin/vercel-build.sh to use the consistent "/6"
denominator (or alternatively revert the header to 5 steps) so every status
message (those emitting "[0/5]" through "[3/5]") matches the header; search for
the literal "/5" progress strings in the script and change them to "/6" and
adjust any incremented step numbers if needed to reflect the actual step
sequence.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d44d589b-3a91-4049-b9ab-e795281a8dcc
📒 Files selected for processing (3)
apps/web-next/src/middleware.tsbin/sync-plugin-registry.tsbin/vercel-build.sh
| // Plugin route mapping: path prefix → plugin name (camelCase DB name). | ||
| // Maps custom route prefixes to their plugin so the middleware can rewrite | ||
| // e.g. /gateway → /plugins/serviceGateway. | ||
| // Keep in sync with WorkflowPlugin.routes / plugin.json. | ||
| // Routes with their own page.tsx (/marketplace, /dashboard) are excluded. | ||
| // /plugins/* paths are handled by the dynamic [pluginName] route automatically. | ||
| const PLUGIN_ROUTE_MAP: Record<string, string> = { | ||
| '/wallet': 'myWallet', | ||
| '/gateway': 'serviceGateway', | ||
| '/gateways': 'gatewayManager', | ||
| '/orchestrators': 'orchestratorManager', | ||
| '/capacity': 'capacityPlanner', | ||
| '/analytics': 'networkAnalytics', | ||
| '/leaderboard': 'networkAnalytics', | ||
| '/forum': 'community', | ||
| '/developers': 'developerApi', | ||
| '/publish': 'pluginPublisher', | ||
| // Note: /marketplace and /dashboard have their own page.tsx files | ||
| '/daydream': 'daydreamVideo', | ||
| '/hello': 'helloWorld', | ||
| '/intelligent-dashboard': 'intelligentDashboard', | ||
| '/todos': 'todoList', | ||
| '/deployments': 'deploymentManager', | ||
| '/lightning-client': 'lightningClient', | ||
| }; |
There was a problem hiding this comment.
Prevention is incomplete while plugin routing remains hardcoded.
Line 7 still requires manual sync, while this PR also generates src/generated/plugin-routes.json. Because middleware keeps a static PLUGIN_ROUTE_MAP, route drift can still reintroduce 404s in future updates. Please wire middleware to generated mappings (or enforce parity in CI) so the prevention step is effective.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web-next/src/middleware.ts` around lines 4 - 27, Replace the hardcoded
PLUGIN_ROUTE_MAP constant in middleware.ts with the generated mapping by
importing the generated plugin-routes.json (e.g., import pluginRoutes from
'plugin-routes.json') and assigning it to PLUGIN_ROUTE_MAP as a typed
Record<string,string>; ensure you cast/validate the imported JSON shape before
use, keep a small fallback to the existing inline map only if the generated JSON
is missing (and log an error), and remove the static entries so middleware
always reads from the generated mapping (referencing the PLUGIN_ROUTE_MAP symbol
and the generated plugin-routes.json filename).
… routes return 404 Root Cause: PR #87 moved 6 plugins from plugins/ to examples/ and simultaneously removed their routes from PLUGIN_ROUTE_MAP in middleware.ts. Since the middleware uses this map to rewrite browser-facing URLs (e.g. /gateway) to the internal plugin loader page (/plugins/serviceGateway), all removed routes returned 404. Additionally, newer plugins like service-gateway, deployment-manager, and lightning-client were never added to the map. Fix: - Restore all 16 plugin route mappings in PLUGIN_ROUTE_MAP - Add auth-route redirect (authenticated users on /login → /dashboard) Prevention: - sync-plugin-registry.ts now generates plugin-routes.json from plugin.json manifests at build time - Reorder vercel-build.sh to run sync-plugin-registry BEFORE Next.js build, so generated files are available to the middleware bundler - Fix connector templates directory path (templates/ → connectors/) Made-with: Cursor
783ee39 to
da5c4c7
Compare
Summary
PLUGIN_ROUTE_MAP(middleware.ts) — routes removed by PR refactor: move 6 non-essential plugins to examples/ #87 and never-added routes for newer plugins (/gateway,/deployments,/lightning-client, etc.)plugin-routes.jsonfrom plugin.json manifests insync-plugin-registry.tsas a prevention mechanismsync-plugin-registrybeforenpm run buildso generated files are available to the middleware bundler/loginare sent to/dashboardtemplates/→connectors/)Root Cause
PR #87 moved 6 plugins to
examples/and removed their routes from the hardcodedPLUGIN_ROUTE_MAPinmiddleware.ts. The middleware uses this map to rewrite browser-facing URLs (e.g./gateway→/plugins/serviceGateway). Without the mapping, Next.js has no matching page and returns 404.The sidebar generates
<Link href="/gateway">fromWorkflowPlugin.routes, so users clicking any plugin in the sidebar hit the 404.Prevention Strategy
sync-plugin-registry.tsnow generatesapps/web-next/src/generated/plugin-routes.jsonfrom each plugin'splugin.jsonroutes at build timevercel-build.shruns registry sync before the Next.js build (was Step 5, now Step 4) so the generated file is available at build timeRelationship to Other PRs
[...slug]/page.tsxas a defense-in-depth fallback; this PR fixes the middleware rewrite which is the primary routing mechanismTest plan
/gatewayloads Service Gateway plugin (was 404)/wallet,/daydream,/orchestrators,/analytics,/leaderboardload their plugins/marketplaceand/dashboardstill work (own page.tsx)/loginredirects to/dashboard/loginMade with Cursor
Summary by CodeRabbit
New Features
Chores