Skip to content

fix(middleware): restore plugin route map — /gateway returns 404#183

Merged
seanhanca merged 1 commit into
mainfrom
fix/middleware-plugin-routes
Mar 4, 2026
Merged

fix(middleware): restore plugin route map — /gateway returns 404#183
seanhanca merged 1 commit into
mainfrom
fix/middleware-plugin-routes

Conversation

@seanhanca
Copy link
Copy Markdown
Contributor

@seanhanca seanhanca commented Mar 4, 2026

Summary

  • Restore all 16 plugin route mappings in 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.)
  • Auto-generate plugin-routes.json from plugin.json manifests in sync-plugin-registry.ts as a prevention mechanism
  • Reorder Vercel build pipeline to run sync-plugin-registry before npm run build so generated files are available to the middleware bundler
  • Add auth-route redirect so authenticated users on /login are sent to /dashboard
  • Fix connector templates directory path (templates/connectors/)

Root Cause

PR #87 moved 6 plugins to examples/ and removed their routes from the hardcoded PLUGIN_ROUTE_MAP in middleware.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"> from WorkflowPlugin.routes, so users clicking any plugin in the sidebar hit the 404.

Prevention Strategy

  1. sync-plugin-registry.ts now generates apps/web-next/src/generated/plugin-routes.json from each plugin's plugin.json routes at build time
  2. vercel-build.sh runs registry sync before the Next.js build (was Step 5, now Step 4) so the generated file is available at build time
  3. Future improvement: middleware can import the generated JSON instead of hardcoding routes, making route additions fully automatic

Relationship to Other PRs

Test plan

  • /gateway loads Service Gateway plugin (was 404)
  • /wallet, /daydream, /orchestrators, /analytics, /leaderboard load their plugins
  • /marketplace and /dashboard still work (own page.tsx)
  • Authenticated /login redirects to /dashboard
  • Unauthenticated plugin route redirects to /login

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Authenticated users are now automatically redirected to the dashboard when attempting to access login or registration pages.
  • Chores

    • Optimized build pipeline sequence and plugin registry synchronization process for improved deployment efficiency.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 4, 2026

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

Project Deployment Actions Updated (UTC)
naap-platform Ready Ready Preview, Comment Mar 4, 2026 8:05pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

Warning

Rate limit exceeded

@seanhanca has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fa1a06c3-a562-48ad-bbcb-92f012f1429e

📥 Commits

Reviewing files that changed from the base of the PR and between 783ee39 and da5c4c7.

📒 Files selected for processing (3)
  • apps/web-next/src/middleware.ts
  • bin/sync-plugin-registry.ts
  • bin/vercel-build.sh
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Middleware Authentication & Routing
apps/web-next/src/middleware.ts
Expanded PLUGIN_ROUTE_MAP with additional path prefixes and added authentication-based redirect logic that redirects already-authenticated users from login/register routes to /dashboard.
Plugin Registry Sync
bin/sync-plugin-registry.ts
Added toCamelCase import, changed gateway templates directory from templates to connectors, and introduced plugin-routes.json generation that maps plugin routes to plugin directory names in camelCase format.
Build Pipeline Reordering
bin/vercel-build.sh
Reordered build steps to execute plugin registry sync before the Next.js build, updated step labels and numbering to reflect six-step pipeline, and removed the separate post-build sync step.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

scope/shell, scope/infra, size/M

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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: restoring the plugin route map to fix /gateway returning 404, which aligns with the primary objective of the PR.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/middleware-plugin-routes

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.

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Invalid import path @naap/cache/rateLimiter causes build failure because the subpath is not exported in the package.json

Fix on Vercel

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f2a1a6 and 783ee39.

📒 Files selected for processing (3)
  • apps/web-next/src/middleware.ts
  • bin/sync-plugin-registry.ts
  • bin/vercel-build.sh

Comment on lines +4 to 27
// 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',
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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).

Comment thread apps/web-next/src/middleware.ts
Comment thread bin/sync-plugin-registry.ts
… 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
@seanhanca seanhanca force-pushed the fix/middleware-plugin-routes branch from 783ee39 to da5c4c7 Compare March 4, 2026 20:02
@seanhanca seanhanca merged commit acce9b5 into main Mar 4, 2026
9 of 10 checks passed
@seanhanca seanhanca deleted the fix/middleware-plugin-routes branch March 4, 2026 20:02
@github-actions github-actions Bot added scope/shell Shell app changes scope/infra Infrastructure changes size/M Medium PR (51-200 lines) labels Mar 4, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 15, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/infra Infrastructure changes scope/shell Shell app changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant