Skip to content

Conversation

@Danilqa
Copy link
Owner

@Danilqa Danilqa commented Nov 22, 2025

Note

Fixes middleware execution for dynamic routes by scoping middleware matching to the matched route’s directory stack, refactors dynamic route parsing, and adds comprehensive tests; also updates website deps and minor CSS.

  • Routing/Middleware:
    • Add parseDynamicRoute utility and use it across dynamic route parsing.
    • Refactor FileRouteResolver:
      • Pass parentRoute and build directoryPaths for Route.
      • Normalize middleware paths; replace inline dynamic-params parser with parseDynamicRoute.
      • Extract matchRoute; change extractMiddlewares to select only middlewares along matchedRoute.directoryPaths.
      • Propagate routeParams to handlers and middleware executor.
    • Update Middleware to build precise regex via parseDynamicRoute and support nesting-level; store path.
    • Extend Route with directoryPaths.
  • Tests:
    • New "static vs dynamic" middleware tests and fixtures (dynamic [id]/apples and static paths) asserting correct middleware order and route params.
    • Adjust existing tests and test utils (support method in middleware runner; expect route params in middleware).
  • Website:
    • Upgrade Docusaurus and related dependencies; tweak announcement bar selector in CSS.

Written by Cursor Bugbot for commit 1ef3190. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Nov 22, 2025

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

Project Deployment Preview Comments Updated (UTC)
node-file-router Ready Ready Preview Comment Nov 22, 2025 5:47pm

@Danilqa
Copy link
Owner Author

Danilqa commented Nov 22, 2025

@cursor review

Copy link

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

This PR fixes a middleware invocation bug where middlewares were not being correctly applied based on the directory hierarchy when both static and dynamic routes coexisted. The fix ensures that only middlewares in the directory path of a matched route are executed, preventing incorrect middleware execution for static routes when dynamic route middlewares were present.

Key Changes:

  • Refactored middleware extraction to use directory-based filtering instead of regex-only matching
  • Added directoryPaths tracking to routes to map their directory hierarchy
  • Updated test expectations to reflect correct middleware execution order
  • Updated Docusaurus and related dependencies to version 3.9.2

Reviewed changes

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

Show a summary per file
File Description
src/file-router.ts Refactored middleware extraction to filter by route's directory paths instead of regex matching
src/components/route/route.ts Added directoryPaths property to track route's directory hierarchy
src/components/route/middleware.ts Added path property and improved regex generation using dynamic route parsing
src/components/file-route-resolver.ts Added buildDirectoryPaths() and normalizeMiddlewarePath() methods, extracted route parsing logic
src/components/dynamic-routes/parse-dynamic-route.ts Extracted dynamic route parsing logic into reusable function
tests/test-utils.ts Added optional method parameter to middleware request runner
tests/request-handle-middlewares.test.ts Updated existing test expectations and added comprehensive test suite for static vs dynamic routes
tests/api-middlewares/static-vs-dynamic/* Added test fixtures for static and dynamic route middleware scenarios
website/package.json Updated Docusaurus to 3.9.2 and @mdx-js/react to 3.1.1
website/src/css/custom.css Updated announcement bar selector for Docusaurus 3.9.2 compatibility
website/docusaurus.config.js Removed backgroundColor (now handled via CSS gradient)
examples/web-socket/package.json Updated ws package to 8.18.1
examples/web-socket/pnpm-lock.yaml Updated lock file for ws 8.18.1
Files not reviewed (1)
  • examples/web-socket/pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Danilqa
Copy link
Owner Author

Danilqa commented Nov 22, 2025

@cursor review

@cursor
Copy link

cursor bot commented Nov 22, 2025

Skipping Bugbot: Bugbot is disabled for this repository

@Danilqa
Copy link
Owner Author

Danilqa commented Nov 22, 2025

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


@Danilqa Danilqa merged commit 2a462d5 into main Nov 22, 2025
5 of 8 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.

2 participants