Skip to content

Commit

Permalink
fix: #6
Browse files Browse the repository at this point in the history
- Use general limiter to do rate limit in every
router
  • Loading branch information
Chinlinlee committed Nov 16, 2022
1 parent 44589d2 commit f66d627
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dotenv": "^6.0.0",
"ejs": "^3.1.2",
"express": "^4.16.3",
"express-rate-limit": "^6.7.0",
"express-session": "^1.16.2",
"fhir": "^4.11.1",
"flat": "^5.0.2",
Expand Down
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');
const RateLimit = require('express-rate-limit');
const bodyParser = require('body-parser');
const http = require('http');
const compress = require('compression');
Expand All @@ -19,6 +20,15 @@ const app = express();

require('rootpath')();
require('dotenv').config();
// limit user only can request 1000 in 1 minute over every routers
let limiter = RateLimit({
windowMs: 1 * 60 * 1000,
max: 1000,
standardHeaders: true,
legacyHeaders: false
});
app.use(limiter);

app.use(compress());
app.use(flash());
app.use(express.static('public'));
Expand Down

0 comments on commit f66d627

Please sign in to comment.