Skip to content

Scan for route-based middleware routes/[server].middleware.ts #3880

Description

@TheAlexLichter

Describe the feature

Middleware can be applied globally or via object syntax at the moment. This makes route (group) based middleware hard to apply and possibly error prone, e.g. forgetting to add authorization to a single endpoint could lead to a security issue and code repetition.

Instead, having route-based middleware with the suffix pattern routes/[server].middleware.ts automatically apply to the route (and all possible child routes) would be helpful, reducing the need for code duplicates and risk of forgetting to add middleware.

Additional information

  • Would you be willing to help implement this feature?

Activity

  1. added
    pending triage
    on Dec 16, 2025
  2. coderabbitai commented on Dec 16, 2025

    @coderabbitai
    Contributor

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees


    Enable issue planning

    To enable issue planning, add the following to your .coderabbit.yaml:

    issue_enrichment:
      planning:
        enabled: true

    You can then request a plan by commenting @coderabbitai plan on any issue.

    🧪 Issue enrichment is currently in early access.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  3. added
    enhancement
    and removed
    pending triage
    on Dec 16, 2025
  4. IslamElsayed commented on Nov 1, 2026

    @IslamElsayed

    Now that the v3 RC is out, I'd like to pick this up, since #4845 reserved the .middleware suffix for it. The plan is to have the route scanner treat routes/[server].middleware.ts as middleware for that route and its child routes, per the issue. Is that the shape you want, and is anyone already on it?

    I use AI assistance when working on patches, and I check and test everything before submitting.

  5. added
    routing
    and removed
    enhancement
    on Nov 10, 2026
  6. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    routing

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions