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:
Cursor Agent
2026-01-14 02:47:01 +00:00
parent 80077ea1af
commit 4f344ff1de
2 changed files with 37 additions and 3 deletions

View File

@@ -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 }