Throw in your next.js project for rate limiting...
A drop in rate limiter designed for web frameworks like next.js. Focus on shipping code and Gr8 limiter will handle rate limiting with limited to no set up.
All the code you need:
route.ts
const client = new Client({
// this will be cleaned up soon...
apiKey: process.env.STRATUS_TOKEN!,
apiURL: "https://gr8-limit-docker.onrender.com/api/v1/ratelimit",
});
export async function POST(req: Next Request){
// Inside a route method
try {
const rateLimited = await client.rateLimit();
if (rateLimited) {
return NextResponse.json(
{ error: "Rate limited." },
{ status: 429 }
);
}
// Rest of ur code...