From 1a85c2571690ba592ac5183d5eadaf9846fe532b Mon Sep 17 00:00:00 2001 From: Factiven Date: Mon, 25 Sep 2023 00:44:40 +0700 Subject: Update v4.1.0 (#79) * Update v4.1.0 * Update pages/_app.js --- pages/api/v2/etc/recent/[page].js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pages/api/v2/etc/recent') diff --git a/pages/api/v2/etc/recent/[page].js b/pages/api/v2/etc/recent/[page].js index 19495c1..6727787 100644 --- a/pages/api/v2/etc/recent/[page].js +++ b/pages/api/v2/etc/recent/[page].js @@ -1,7 +1,19 @@ +import { rateLimiterRedis, redis } from "@/lib/redis"; + const API_URL = process.env.API_URI; export default async function handler(req, res) { try { + if (redis) { + try { + const ipAddress = req.socket.remoteAddress; + await rateLimiterRedis.consume(ipAddress); + } catch (error) { + return res.status(429).json({ + error: `Too Many Requests, retry after ${error.msBeforeNext / 1000}`, + }); + } + } const page = req.query.page || 1; var hasNextPage = true; -- cgit v1.2.3