mirror of
https://github.com/koreanbots/core.git
synced 2025-12-17 06:40:24 +00:00
chore: added endpoints to ignore ratelmit
This commit is contained in:
parent
6d74f88d50
commit
9bbd155573
@ -179,6 +179,10 @@ export const KoreanbotsEndPoints = {
|
|||||||
logout: '/api/auth/discord/logout'
|
logout: '/api/auth/discord/logout'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const GlobalRatelimitIgnore = [
|
||||||
|
'/api/image/discord/avatars/'
|
||||||
|
]
|
||||||
|
|
||||||
export const Oauth = {
|
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`
|
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`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import nc from 'next-connect'
|
import nc from 'next-connect'
|
||||||
import rateLimit from 'express-rate-limit'
|
import rateLimit from 'express-rate-limit'
|
||||||
|
|
||||||
import ResponseWrapper from '@utils/ResponseWrapper'
|
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||||
|
import { GlobalRatelimitIgnore } from '@utils/Constants'
|
||||||
|
|
||||||
const limiter = rateLimit({
|
const limiter = rateLimit({
|
||||||
windowMs: 60 * 1000,
|
windowMs: 60 * 1000,
|
||||||
@ -9,7 +11,10 @@ const limiter = rateLimit({
|
|||||||
statusCode: 429,
|
statusCode: 429,
|
||||||
handler: (_req, res) => ResponseWrapper(res, { code: 429 }),
|
handler: (_req, res) => ResponseWrapper(res, { code: 429 }),
|
||||||
keyGenerator: (req) => req.headers['x-forwarded-for'] as string,
|
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 = () =>
|
const RequestHandler = () =>
|
||||||
nc<NextApiRequest, NextApiResponse>({
|
nc<NextApiRequest, NextApiResponse>({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user