Skip to content

Commit 2210039

Browse files
committed
- adds rate-limiting
- adds type definitions for easier exploration
1 parent 1853b7e commit 2210039

File tree

3 files changed

+95
-12
lines changed

3 files changed

+95
-12
lines changed

app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import express from 'express';
22
import path from 'path';
33
import logger from 'morgan';
44
import bodyParser from 'body-parser';
5+
import RateLimit from 'express-rate-limit';
56

67
import { authRouter } from './routes/auth';
78
import { listenRouter } from './routes/listen';
89

910
export const app = express();
1011

12+
const limiter = new RateLimit({
13+
windowMs: 2 * 60 * 1000, // 2 minutes
14+
max: 2400, // 20 rps, these values should be adjusted for production use depending on your infrastructure and the volume of notifications you expect
15+
});
16+
1117
const env = process.env.NODE_ENV || 'development';
1218
app.locals.ENV = env;
1319
app.locals.ENV_DEVELOPMENT = (env === 'development');
@@ -24,6 +30,7 @@ app.use(express.static(path.join(__dirname, 'public')));
2430

2531
app.use('/', authRouter);
2632
app.use('/listen', listenRouter);
33+
app.use(limiter);
2734

2835
// catch 404 and forward to error handler
2936
app.use((req, res, next) => {

package-lock.json

Lines changed: 79 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"body-parser": "^1.19.0",
1515
"escape-html": "^1.0.3",
1616
"express": "^4.17.1",
17+
"express-rate-limit": "^5.1.3",
1718
"isomorphic-fetch": "^2.2.1",
1819
"jsonwebtoken": "^8.5.1",
1920
"jwks-rsa": "^1.8.0",
@@ -28,8 +29,16 @@
2829
"@babel/core": "^7.10.2",
2930
"@babel/node": "^7.10.1",
3031
"@babel/preset-env": "^7.10.2",
32+
"@types/body-parser": "^1.19.0",
3133
"@types/escape-html": "^1.0.0",
34+
"@types/express": "^4.17.6",
35+
"@types/express-rate-limit": "^5.0.0",
3236
"@types/jsonwebtoken": "^8.5.0",
37+
"@types/morgan": "^1.9.1",
38+
"@types/pem": "^1.9.5",
39+
"@types/pug": "^2.0.4",
40+
"@types/socket.io": "^2.1.8",
41+
"@types/sqlite3": "^3.1.6",
3342
"babel-eslint": "^10.1.0",
3443
"eslint": "^7.2.0",
3544
"eslint-config-airbnb": "^18.1.0",

0 commit comments

Comments
 (0)