Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/api/send-review/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { NextResponse } from 'next/server';
import nodemailer from 'nodemailer';

// Simple in-memory rate limiter: max 5 requests per IP per 15 minutes
const rateLimit = new Map();
const LIMIT = 5;
const WINDOW_MS = 15 * 60 * 1000;

function isRateLimited(ip) {
const now = Date.now();
const entry = rateLimit.get(ip) || { count: 0, start: now };
if (now - entry.start > WINDOW_MS) { rateLimit.set(ip, { count: 1, start: now }); return false; }
if (entry.count >= LIMIT) return true;
entry.count++;
rateLimit.set(ip, entry);
return false;
}

export async function POST(request) {
const ip = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || 'unknown';
if (isRateLimited(ip)) {
return NextResponse.json({ success: false, error: 'Too many requests' }, { status: 429 });
}
const { name, email, review, rating, to } = await request.json();

try {
Expand Down
Loading