Skip to content

Commit c84ac17

Browse files
committed
Merge branch 'release/0.2.1-beta'
2 parents 307d854 + c4580a6 commit c84ac17

12 files changed

+41
-18
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.4.1] - 2018-02-04
10+
11+
### Changed
12+
- Fixed api requests overflooding.
13+
914
## [0.4.0] - 2018-02-04
1015

1116
### BREAKING CHANGE

build/asset-manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"main.css": "static/css/main.ef153f8d.css",
33
"main.css.map": "static/css/main.ef153f8d.css.map",
4-
"main.js": "static/js/main.db092208.js",
5-
"main.js.map": "static/js/main.db092208.js.map"
4+
"main.js": "static/js/main.c68bff14.js",
5+
"main.js.map": "static/js/main.c68bff14.js.map"
66
}

build/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"><title>Nelson Monitor</title><link href="/static/css/main.ef153f8d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.db092208.js"></script></body></html>
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"><title>Nelson Monitor</title><link href="/static/css/main.ef153f8d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.c68bff14.js"></script></body></html>

build/nelson.gui.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ var request = require('request');
77
var md5 = require('md5');
88
var crypto = require('crypto');
99
var express = require('express');
10+
var throttle = require("express-throttle");
1011
var bodyParser = require('body-parser');
1112
var program = require('commander');
1213
var path = require('path');
1314
var app = express();
1415
var version = require('../package.json').version;
1516

17+
var apiThrottleOptions = {
18+
"burst": 5,
19+
"rate": "10/min"
20+
};
21+
1622
var parseNumber = function parseNumber(v) {
1723
return parseInt(v);
1824
};
@@ -29,8 +35,8 @@ app.set('port', process.env.NELSON_GUI_PORT || program.port);
2935
app.use(express.static(path.join(__dirname)));
3036
app.use(bodyParser.urlencoded({ extended: false }));
3137
app.use(bodyParser.json());
32-
app.get('/api', proxy);
33-
app.get('/api/peers', proxy);
38+
app.get('/api', throttle(apiThrottleOptions), proxy);
39+
app.get('/api/peers', throttle(apiThrottleOptions), proxy);
3440

3541
var salt = crypto.randomBytes(48).toString('hex');
3642
// Listen for requests
@@ -64,7 +70,7 @@ function proxy(req, resp) {
6470
return;
6571
}
6672
if (r.statusCode === 401) {
67-
console.log('Remote access denied');
73+
console.log('Remote access denied', req.query, opts);
6874
resp.status(401);
6975
return;
7076
}

build/service-worker.js

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

build/static/js/main.db092208.js build/static/js/main.c68bff14.js

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

build/static/js/main.c68bff14.js.map

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

build/static/js/main.db092208.js.map

-1
This file was deleted.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nelson.gui",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/SemkoDev/nelson.gui.git"
@@ -31,6 +31,7 @@
3131
"body-parser": "^1.18.2",
3232
"classnames": "^2.2.5",
3333
"commander": "^2.12.2",
34+
"express-throttle": "^2.0.0",
3435
"lodash": "^4.17.4",
3536
"material-ui": "^0.20.0",
3637
"md5": "^2.2.1",

src/App.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class App extends Component {
3636
}
3737

3838
componentDidMount () {
39-
this.props.getNelsonData();
39+
this.startPoll();
4040
if (this.props.match.params.auth) {
4141
this.props.changeConnection(this.props.match.params);
4242
}
4343
}
4444

4545
componentWillUnmount() {
46-
clearTimeout(this.timeout);
46+
this.timeout && clearInterval(this.timeout);
4747
}
4848

4949
componentWillReceiveProps(nextProps) {
@@ -101,8 +101,7 @@ class App extends Component {
101101
}
102102

103103
startPoll () {
104-
this.props.getNelsonData().then(this.props.getNelsonPeers())
105-
this.timeout = setTimeout(() => {
104+
this.timeout = setInterval(() => {
106105
this.props.getNelsonData().then(this.props.getNelsonPeers())
107106
}, this.props.updateInterval);
108107
}

src/nelson.gui.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ const request = require('request');
33
const md5 = require('md5');
44
const crypto = require('crypto');
55
const express = require('express');
6+
const throttle = require("express-throttle");
67
const bodyParser = require('body-parser');
78
const program = require('commander');
89
const path = require('path');
910
const app = express();
1011
const version = require('../package.json').version;
1112

13+
const apiThrottleOptions = {
14+
"burst": 5,
15+
"rate": "10/min"
16+
};
17+
1218
const parseNumber = (v) => parseInt(v);
1319

1420
process.on('unhandledRejection', (reason, p) => {
@@ -28,8 +34,8 @@ app.set('port', process.env.NELSON_GUI_PORT || program.port);
2834
app.use(express.static(path.join(__dirname)));
2935
app.use(bodyParser.urlencoded({ extended: false }));
3036
app.use(bodyParser.json());
31-
app.get('/api', proxy);
32-
app.get('/api/peers', proxy);
37+
app.get('/api', throttle(apiThrottleOptions), proxy);
38+
app.get('/api/peers', throttle(apiThrottleOptions), proxy);
3339

3440
const salt = crypto.randomBytes(48).toString('hex');
3541
// Listen for requests
@@ -62,7 +68,7 @@ function proxy (req, resp) {
6268
return;
6369
}
6470
if (r.statusCode === 401) {
65-
console.log('Remote access denied');
71+
console.log('Remote access denied', req.query, opts);
6672
resp.status(401);
6773
return;
6874
}

yarn.lock

+6
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,12 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
25642564
dependencies:
25652565
homedir-polyfill "^1.0.1"
25662566

2567+
express-throttle@^2.0.0:
2568+
version "2.0.0"
2569+
resolved "https://registry.yarnpkg.com/express-throttle/-/express-throttle-2.0.0.tgz#371cca348a82ccf2b924379119df7e73c05f6acf"
2570+
dependencies:
2571+
lru-cache "^4.0.1"
2572+
25672573
express@^4.13.3:
25682574
version "4.16.2"
25692575
resolved "https://registry.yarnpkg.com/express/-/express-4.16.2.tgz#e35c6dfe2d64b7dca0a5cd4f21781be3299e076c"

0 commit comments

Comments
 (0)