From 9f76a3c9dd13f3564475c64eb4e01a4dcee507b0 Mon Sep 17 00:00:00 2001 From: hobokenchicken Date: Thu, 23 Apr 2026 12:56:47 -0400 Subject: [PATCH] fix: increase rate limit to 1000/15min, add WatchHistory error handling --- backend/src/index.ts | 20 +++++++------- .../app/dashboard/components/WatchHistory.tsx | 26 +++++++++++++++++-- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 8c91350..6fa4998 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,13 +1,13 @@ -import express from "express"; import cors from "cors"; -import helmet from "helmet"; -import morgan from "morgan"; -import rateLimit from "express-rate-limit"; -import { createServer } from "http"; -import { Server } from "socket.io"; import dotenv from "dotenv"; +import express from "express"; +import rateLimit from "express-rate-limit"; import fs from "fs"; +import helmet from "helmet"; +import { createServer } from "http"; +import morgan from "morgan"; import path from "path"; +import { Server } from "socket.io"; // BigInt JSON support - MUST BE BEFORE ROUTERS (BigInt.prototype as any).toJSON = function () { @@ -61,12 +61,12 @@ app.use( }), ); -// Rate limiting +// Rate limiting - generous for small user base const limiter = rateLimit({ - windowMs: 15 * 60 * 1000, // 15 minutes - max: 100, // limit each IP to 100 requests per windowMs + windowMs: 15 * 60 * 1000, + max: 1000, }); -app.use(limiter); +app.use("/api", limiter); // Body parsing app.use(express.json({ limit: "10mb" })); diff --git a/frontend/src/app/dashboard/components/WatchHistory.tsx b/frontend/src/app/dashboard/components/WatchHistory.tsx index 61ee384..a68e3ef 100644 --- a/frontend/src/app/dashboard/components/WatchHistory.tsx +++ b/frontend/src/app/dashboard/components/WatchHistory.tsx @@ -1,6 +1,6 @@ "use client"; -import { Clock, Egg, Film, Tv } from "lucide-react"; +import { AlertTriangle, Clock, Egg, Film, Tv } from "lucide-react"; import { useEffect, useState } from "react"; import { userApi } from "@/lib/api"; import { formatNumber } from "@/lib/utils"; @@ -8,11 +8,22 @@ import { formatNumber } from "@/lib/utils"; export function WatchHistory() { const [events, setEvents] = useState([]); const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); useEffect(() => { userApi .getWatchHistory(1, 50) - .then((r) => setEvents(r.data.events || [])) + .then((r) => { + setEvents(r.data.events || []); + setError(null); + }) + .catch((err) => { + setError( + err?.response?.status === 429 + ? "Slow down, chicken!" + : "Failed to load history", + ); + }) .finally(() => setLoading(false)); }, []); @@ -20,6 +31,17 @@ export function WatchHistory() { return (
Peeking at history...
); + + if (error) + return ( +
+
🐔
+
+ {error} +
+
+ ); + if (events.length === 0) return (