Skip to content

fix(kitojs): middleware propagation and mounting with router - #38

Merged
nehu3n merged 1 commit into
kitojs:mainfrom
skick1234:fix-mounting
Dec 19, 2025
Merged

fix(kitojs): middleware propagation and mounting with router#38
nehu3n merged 1 commit into
kitojs:mainfrom
skick1234:fix-mounting

Conversation

@skick1234

Copy link
Copy Markdown
Contributor

Issue

Follow router.use() docs:

  /**
   * Registers a global middleware that runs for all routes in this router.
   *
   * @param middleware - Middleware function or definition
   * @returns The router instance for chaining
   *
   * @example
   * ```typescript
   * router.use((ctx, next) => {
   *   console.log(`${ctx.req.method} ${ctx.req.url}`);
   *   next();
   * });
   * ```
   */

When using router.mount(path, subRouter), any middleware defined on the subRouter via .use() was silently ignored. Only the middleware defined directly on the routes themselves (e.g., in .get('/path', [mw], handler)) were preserved.

Key changes

  • Modified mount() to retrieve the sub-router's middleware stack
  • Improved path normalization to handle the root / prefix correctly
  • Prepended these middlewares to every imported route, ensuring proper inheritance
  • Simplified the mount override to rely on super.mount() for path prefixing and middleware merging
  • Create test cases for router

@nehu3n
nehu3n merged commit c2a90fc into kitojs:main Dec 19, 2025
2 checks passed
@nehu3n

nehu3n commented Dec 19, 2025

Copy link
Copy Markdown
Member

Thank you so much!

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