Skip to content

Releases: daveyplate/next-rate-limit

Upstash!

14 Dec 01:33
Compare
Choose a tag to compare

Installation

npm install @daveyplate/next-rate-limit@latest

You can now optionally opt for Upstash rate limiting for distributed rate limits, if you have high volume and the in-memory store won't do the trick. It will load your environment variables UPSTASH_REDIS_REST_URL & UPSTASH_REDIS_REST_TOKEN directly from Vercel integration, or you can supply url and token paremeters to the upstash object on the configuration.

Example:

import { rateLimit } from '@daveyplate/next-rate-limit'
import { NextRequest, NextResponse } from 'next/server'

export async function middleware(request: NextRequest) {
    const response = NextResponse.next()

    // Rate Limiting
    return await rateLimit({ request, response, upstash: { enabled: true, analytics: true } })
}

// Apply middleware to all API routes
export const config = {
    matcher: '/api/:path*'
}