aboutsummaryrefslogtreecommitdiff
path: root/pages/api/v2/etc/recent
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-09-25 00:44:40 +0700
committerGitHub <[email protected]>2023-09-25 00:44:40 +0700
commit1a85c2571690ba592ac5183d5eadaf9846fe532b (patch)
tree3f3552c00cd49c0eeab5275275cf5cf5666e5027 /pages/api/v2/etc/recent
parentDelete .github/workflows/deploy.yml (diff)
downloadmoopa-4.1.0.tar.xz
moopa-4.1.0.zip
Update v4.1.0 (#79)v4.1.0
* Update v4.1.0 * Update pages/_app.js
Diffstat (limited to 'pages/api/v2/etc/recent')
-rw-r--r--pages/api/v2/etc/recent/[page].js12
1 files changed, 12 insertions, 0 deletions
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;