Back to MD Exchange
    Project Blueprintsnextjsmiddlewareauthi18n

    Next.js 15 Middleware Recipes

    12 middleware patterns: auth guards, i18n routing, A/B testing, rate limiting, geo-redirect, bot detection.

    M
    marcuschen|March 25, 2026|Updated Oct 8
    120 downloads78 stars

    Uploaded markdown content, not a verification of tool compatibility or results. Review the raw text, commands, and permissions before using it. Stars require an account.


    name: nextjs-middleware-recipes


    Next.js 15 Middleware Recipes

    1. Auth Guard

    Redirect unauthenticated users from protected routes.

    2. i18n Routing

    Detect language from Accept-Language header.

    3. A/B Testing

    Assign variant via cookie, rewrite to variant page.

    4. Rate Limiting

    Token bucket per IP using edge KV store.

    5. Geo Redirect

    Redirect based on Cloudflare geo headers.

    6. Bot Detection

    Block bad bots, allow search engine crawlers.

    7. Maintenance Mode

    Show maintenance page when env flag is set.

    8. CORS Headers

    9. CSP Headers

    10. Trailing Slash Normalization

    11. Feature Flags

    12. Request Logging