fix: increase rate limit to 1000/15min, add WatchHistory error handling
This commit is contained in:
+10
-10
@@ -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" }));
|
||||
|
||||
@@ -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<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(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 (
|
||||
<div className="p-4 font-bold animate-pulse">Peeking at history...</div>
|
||||
);
|
||||
|
||||
if (error)
|
||||
return (
|
||||
<div className="text-center py-10">
|
||||
<div className="text-5xl mb-4">🐔</div>
|
||||
<div className="font-black uppercase tracking-widest text-sm text-destructive flex items-center justify-center gap-2">
|
||||
<AlertTriangle className="h-4 w-4" /> {error}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (events.length === 0)
|
||||
return (
|
||||
<div className="text-center py-10 opacity-40">
|
||||
|
||||
Reference in New Issue
Block a user