Fix: stabilize ActivityFeed UI on reload
Avoid shared dev rate-limit bucket for n8n status and fall back to a stable offline state when the status call fails, preventing the widget from getting stuck in the small translucent loading UI.
This commit is contained in:
@@ -6,10 +6,21 @@ export const revalidate = 30;
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
// Rate limiting for n8n status endpoint
|
||||
const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
|
||||
const ip =
|
||||
request.headers.get("x-forwarded-for") ||
|
||||
request.headers.get("x-real-ip") ||
|
||||
"unknown";
|
||||
const ua = request.headers.get("user-agent") || "unknown";
|
||||
const { checkRateLimit } = await import('@/lib/auth');
|
||||
|
||||
if (!checkRateLimit(ip, 30, 60000)) { // 30 requests per minute for status
|
||||
// In dev, many requests can share ip=unknown; use UA to avoid a shared bucket.
|
||||
const rateKey =
|
||||
process.env.NODE_ENV === "development" && ip === "unknown"
|
||||
? `ua:${ua.slice(0, 120)}`
|
||||
: ip;
|
||||
const maxPerMinute = process.env.NODE_ENV === "development" ? 300 : 30;
|
||||
|
||||
if (!checkRateLimit(rateKey, maxPerMinute, 60000)) { // requests per minute
|
||||
return NextResponse.json(
|
||||
{ error: 'Rate limit exceeded. Please try again later.' },
|
||||
{ status: 429 }
|
||||
|
||||
Reference in New Issue
Block a user