Skip to content

Commit

Permalink
Add IP limit
Browse files Browse the repository at this point in the history
  • Loading branch information
stoodkev committed Apr 17, 2018
1 parent 864a656 commit 1cfa107
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app.js
Expand Up @@ -3,7 +3,17 @@ var bodyParser = require("body-parser");
var routes = require("./routes/routes.js");
var app = express();
require('dotenv').config();
var RateLimit = require('express-rate-limit');

app.enable('trust proxy'); // only if you're behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc)

var limiter = new RateLimit({
windowMs: 60*1000, // 1 minute
max: 20, // limit each IP to 20 requests per windowMs
delayMs: 0 // disable delaying - full speed until the max limit is reached
});
// apply to all requests
app.use(limiter);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Expand Down
21 changes: 21 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
Expand Up @@ -7,6 +7,7 @@
"body-parser": "^1.18.2",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"express-rate-limit": "^2.11.0",
"mssql": "^4.1.0"
},
"devDependencies": {},
Expand Down
16 changes: 16 additions & 0 deletions routes/routes.js
Expand Up @@ -58,6 +58,22 @@ app.get("/api/get-witnesses-rank", function(req, res){
sql.close();});
});

app.get("/api/get-incoming-witness-votes/:username", function(req, res){
console.log(config.config_api);
sql.connect(config.config_api).then(pool => {
console.log("connected");
return pool.request()
.input("username",req.params.username)
.query('Select Witnesses.name, rank\
from Witnesses (NOLOCK)\
LEFT JOIN (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT votes) DESC) AS rank, * FROM Witnesses (NOLOCK) WHERE signing_key != \'STM1111111111111111111111111111111114T1Anm\') AS rankedTable ON Witnesses.name = rankedTable.name;')
}).then(result => {
res.status(200).send(result.recordsets[0]);
sql.close();
}).catch(error => {console.log(error);
sql.close();});
});

}

module.exports = appRouter;

0 comments on commit 1cfa107

Please sign in to comment.