added express-rate-limit middleware to Web UI

pull/61/MERGE
13621160019@163.com 2021-08-16 16:41:07 +08:00
parent 98f09259db
commit 9db895d191
1 changed files with 10 additions and 1 deletions

11
web/server.js vendored
View File

@ -1,11 +1,20 @@
const compression = require('compression');
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
app.use(compression());
app.disable('x-powered-by');
app.use(express.static(path.join(__dirname, 'build')));
// set up rate limiter: maximum of five requests per minute
var RateLimit = require('express-rate-limit');
var limiter = new RateLimit({
windowMs: 1*60*1000, // 1 minute
max: 5 // limit each IP to 5 requests per windowMs
});
// apply rate limiter to all requests
app.use(limiter);
// need to declare a "catch all" route on your express server
// that captures all page requests and directs them to the client
// the react-router do the route part