better env name RATE_LIMIT_WINDOWS_MINS

This commit is contained in:
Dave Horton
2022-04-05 17:29:58 -04:00
parent 8097f0afda
commit 8c54e80d46
2 changed files with 3 additions and 4 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ const unless = (paths, middleware) => {
};
const limiter = rateLimit({
windowMs: (process.env.RATE_LIMIT_WINDOWS_MS || 5) * 60 * 1000, // 5 minutes
windowMs: (process.env.RATE_LIMIT_WINDOWS_MINS || 5) * 60 * 1000, // 5 minutes
max: process.env.RATE_LIMIT_MAX_PER_WINDOW || 600, // Limit each IP to 600 requests per `window`
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
@@ -1,10 +1,10 @@
const router = require('express').Router();
const {DbErrorBadRequest} = require('../../utils/errors');
const PredefinedCarrier = require('../../models/predefined-carrier');
const VoipCarrier = require('../../models/voip-carrier');
const SipGateway = require('../../models/sip-gateway');
const SmppGateway = require('../../models/smpp-gateway');
const {parseServiceProviderSid} = require('./utils');
const short = require('short-uuid');
const {promisePool} = require('../../db');
const sysError = require('../error');
@@ -43,8 +43,7 @@ router.post('/:sid', async(req, res) => {
await promisePool.query(sqlSelectCarrierByNameForSP, [service_provider_sid, template.name]);
if (r2.length > 0) {
logger.info({account_sid}, `Failed to add carrier with name ${template.name}, carrier of that name exists`);
throw new DbErrorBadRequest(`A carrier with name ${template.name} already exists`);
template.name = `${template.name}-${short.generate()}`;
}
/* retrieve all the sip gateways */