Skip to content

Instantly share code, notes, and snippets.

View lahin31's full-sized avatar
🎯
Focusing

Lahin lahin31

🎯
Focusing
View GitHub Profile
@lahin31
lahin31 / rate_limit_next.js
Created November 14, 2023 05:38
Rate Limit for a Nextjs Serverless API
import { LRUCache } from 'lru-cache';
const rateLimit = (options) => {
const tokenCache = new LRUCache({
max: options?.uniqueTokenPerInterval || 500,
ttl: options?.interval || 60000,
})
return {
check: (res, limit, token) =>
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://localhost:3000;