feat: Add request rate limiter based on IP address (#8174)
This commit is contained in:
@@ -179,7 +179,7 @@ class ParseServer {
|
||||
* Create an express app for the parse server
|
||||
* @param {Object} options let you specify the maxUploadSize when creating the express app */
|
||||
static app(options) {
|
||||
const { maxUploadSize = '20mb', appId, directAccess, pages } = options;
|
||||
const { maxUploadSize = '20mb', appId, directAccess, pages, rateLimit = [] } = options;
|
||||
// This app serves the Parse API directly.
|
||||
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API.
|
||||
var api = express();
|
||||
@@ -214,6 +214,11 @@ class ParseServer {
|
||||
api.use(bodyParser.json({ type: '*/*', limit: maxUploadSize }));
|
||||
api.use(middlewares.allowMethodOverride);
|
||||
api.use(middlewares.handleParseHeaders);
|
||||
const routes = Array.isArray(rateLimit) ? rateLimit : [rateLimit];
|
||||
for (const route of routes) {
|
||||
middlewares.addRateLimit(route, options);
|
||||
}
|
||||
api.use(middlewares.handleParseSession);
|
||||
|
||||
const appRouter = ParseServer.promiseRouter({ appId });
|
||||
api.use(appRouter.expressRouter());
|
||||
|
||||
Reference in New Issue
Block a user