mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-21 12:49:07 +00:00
fix: align with express-rate-limit v6
This commit is contained in:
parent
28ba5834ea
commit
be345e3d34
@ -161,7 +161,7 @@ module.exports = {
|
|||||||
/*
|
/*
|
||||||
Rate limits.
|
Rate limits.
|
||||||
Please be aware that these apply to all users, including site owners.
|
Please be aware that these apply to all users, including site owners.
|
||||||
https://github.com/nfriedly/express-rate-limit#configuration-options
|
https://github.com/nfriedly/express-rate-limit#usage
|
||||||
*/
|
*/
|
||||||
rateLimits: [
|
rateLimits: [
|
||||||
{
|
{
|
||||||
@ -172,6 +172,8 @@ module.exports = {
|
|||||||
config: {
|
config: {
|
||||||
windowMs: 1000,
|
windowMs: 1000,
|
||||||
max: 10,
|
max: 10,
|
||||||
|
legacyHeaders: true,
|
||||||
|
standardHeaders: true,
|
||||||
message: {
|
message: {
|
||||||
success: false,
|
success: false,
|
||||||
description: 'Rate limit reached, please try again in a while.'
|
description: 'Rate limit reached, please try again in a while.'
|
||||||
@ -187,6 +189,8 @@ module.exports = {
|
|||||||
config: {
|
config: {
|
||||||
windowMs: 5 * 1000,
|
windowMs: 5 * 1000,
|
||||||
max: 2,
|
max: 2,
|
||||||
|
legacyHeaders: true,
|
||||||
|
standardHeaders: true,
|
||||||
message: {
|
message: {
|
||||||
success: false,
|
success: false,
|
||||||
description: 'Rate limit reached, please try again in 5 seconds.'
|
description: 'Rate limit reached, please try again in 5 seconds.'
|
||||||
@ -200,7 +204,9 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
config: {
|
config: {
|
||||||
windowMs: 30 * 1000,
|
windowMs: 30 * 1000,
|
||||||
max: 6
|
max: 6,
|
||||||
|
legacyHeaders: true,
|
||||||
|
standardHeaders: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -211,6 +217,8 @@ module.exports = {
|
|||||||
config: {
|
config: {
|
||||||
windowMs: 60 * 1000,
|
windowMs: 60 * 1000,
|
||||||
max: 1,
|
max: 1,
|
||||||
|
legacyHeaders: true,
|
||||||
|
standardHeaders: true,
|
||||||
message: {
|
message: {
|
||||||
success: false,
|
success: false,
|
||||||
description: 'Rate limit reached, please try again in 60 seconds.'
|
description: 'Rate limit reached, please try again in 60 seconds.'
|
||||||
|
@ -17,7 +17,7 @@ const express = require('express')
|
|||||||
const helmet = require('helmet')
|
const helmet = require('helmet')
|
||||||
const nunjucks = require('nunjucks')
|
const nunjucks = require('nunjucks')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const RateLimit = require('express-rate-limit')
|
const rateLimit = require('express-rate-limit')
|
||||||
const readline = require('readline')
|
const readline = require('readline')
|
||||||
const serveStatic = require('@bobbywibowo/serve-static')
|
const serveStatic = require('@bobbywibowo/serve-static')
|
||||||
const { accessSync, constants } = require('fs')
|
const { accessSync, constants } = require('fs')
|
||||||
@ -83,9 +83,9 @@ safe.enable('view cache')
|
|||||||
|
|
||||||
// Configure rate limits
|
// Configure rate limits
|
||||||
if (Array.isArray(config.rateLimits) && config.rateLimits.length) {
|
if (Array.isArray(config.rateLimits) && config.rateLimits.length) {
|
||||||
for (const rateLimit of config.rateLimits) {
|
for (const _rateLimit of config.rateLimits) {
|
||||||
const limiter = new RateLimit(rateLimit.config)
|
const limiter = rateLimit(_rateLimit.config)
|
||||||
for (const route of rateLimit.routes) {
|
for (const route of _rateLimit.routes) {
|
||||||
safe.use(route, limiter)
|
safe.use(route, limiter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user