chore: added endpoints to ignore ratelmit

This commit is contained in:
wonderlandpark 2021-03-05 10:57:24 +09:00
parent 6d74f88d50
commit 9bbd155573
2 changed files with 10 additions and 1 deletions

View File

@ -179,6 +179,10 @@ export const KoreanbotsEndPoints = {
logout: '/api/auth/discord/logout'
}
export const GlobalRatelimitIgnore = [
'/api/image/discord/avatars/'
]
export const Oauth = {
discord: (clientID: string, scope: string) => `https://discord.com/oauth2/authorize?client_id=${clientID}&scope=${scope}&permissions=0&response_type=code&redirect_uri=${process.env.KOREANBOTS_URL}/api/auth/discord/callback&prompt=none`
}

View File

@ -1,7 +1,9 @@
import { NextApiRequest, NextApiResponse } from 'next'
import nc from 'next-connect'
import rateLimit from 'express-rate-limit'
import ResponseWrapper from '@utils/ResponseWrapper'
import { GlobalRatelimitIgnore } from '@utils/Constants'
const limiter = rateLimit({
windowMs: 60 * 1000,
@ -9,7 +11,10 @@ const limiter = rateLimit({
statusCode: 429,
handler: (_req, res) => ResponseWrapper(res, { code: 429 }),
keyGenerator: (req) => req.headers['x-forwarded-for'] as string,
skip: (req) => {
if(GlobalRatelimitIgnore.map(el => req.url.startsWith(el)).find(el => el)) return true
return false
}
})
const RequestHandler = () =>
nc<NextApiRequest, NextApiResponse>({