Skip to content

Commit f7eab33

Browse files
add rate limiting
1 parent 805cea0 commit f7eab33

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ☁️nelson-cloud
2+
23
![Build Status](https://github.com/Nelson-numerical-software/nelson-cloud/workflows/Node.js%20CI/badge.svg)
34
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
45
[![GitHub license](https://img.shields.io/badge/license-GPL2-blue.svg)](https://github.com/Nelson-numerical-software/nelson-cloud/blob/master/COPYING.md)

lib/nelsonSocketIO.js

+7
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@ const app = express();
2727
const child_process = require('child_process');
2828
const findFreePort = require('find-free-port');
2929
const nelsonProcess = require('./nelsonProcess');
30+
const RateLimit = require('express-rate-limit');
3031
//=============================================================================
3132
function nelsonSocketIO() {
3233
const server = http.Server(app);
3334
const io = socketio(server);
3435
//=============================================================================
3536
server.listen(CONFIGURATION.PORT);
3637
//=============================================================================
38+
const limiter = new RateLimit({
39+
windowMs: 1 * 60 * 1000, // 1 minute
40+
max: 50,
41+
});
42+
//=============================================================================
3743
app.use(express.static(__dirname + '/../resources'));
44+
app.use(limiter);
3845
app.get('/', function (req, res) {
3946
res.sendFile(__dirname + '/resources/index.html');
4047
});

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"dependencies": {
4949
"child_process": "1.0.2",
5050
"express": "4.17.1",
51+
"express-rate-limit": "5.2.3",
5152
"find-free-port": "2.0.0",
5253
"ip": "1.1.5",
5354
"socket.io": "3.1.0",

0 commit comments

Comments
 (0)