forked from lukePeavey/quotable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrateLimit.js
24 lines (22 loc) · 801 Bytes
/
rateLimit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import rateLimit from 'express-rate-limit'
const LIMIT = process.env.RATE_LIMIT || 180
const MINUTE = 60 * 1000
const HOUR = 60 * 60 * 1000
// Rate limit settings
// Sets a rate limit of 150 requests per minute (by IP address)
export default rateLimit({
// The maximum number of requests that can be made within the specified time window
max: LIMIT,
// The time window for the the rate limit
windowMs: MINUTE,
// Return rate limit info in the `RateLimit-*` headers
standardHeaders: true,
// Disable the `X-RateLimit-*` headers
legacyHeaders: false,
// Handle response when rate limit has been exceeded
handler: (_, response) => {
const statusCode = 429
const statusMessage = 'Too Many Requests'
response.status(statusCode).json({ statusCode, statusMessage })
},
})