added ip filter
This commit is contained in:
parent
28bf2f57c5
commit
5c9c907d61
24
server.js
24
server.js
@ -12,12 +12,12 @@ const https = require('https');
|
||||
const apicache = require('apicache');
|
||||
|
||||
const ipfilter = require('express-ipfilter').IpFilter;
|
||||
const IpDeniedError = require('express-ipfilter').IpDeniedError;
|
||||
|
||||
const port = process.env.PORT || 8080;
|
||||
|
||||
logger.level = 'debug';
|
||||
|
||||
app.use(ipfilter(ips, { 'mode': 'allow' }));
|
||||
// app.use(compression());
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ 'extended': true }));
|
||||
@ -25,7 +25,7 @@ app.use(bodyParser.urlencoded({ 'extended': true }));
|
||||
apicache.options({ 'debug': true });
|
||||
const cache = apicache.middleware;
|
||||
|
||||
app.use(cache('15 minutes'));
|
||||
// app.use(cache('15 minutes'));
|
||||
|
||||
// const ips = ['212.71.255.44', '82.35.75.161'];
|
||||
|
||||
@ -33,6 +33,22 @@ const ips = ['212.71.255.44'];
|
||||
|
||||
app.use(ipfilter(ips, { 'mode': 'allow' }));
|
||||
|
||||
app.use((err, req, res, _next) => {
|
||||
console.log('Error handler', err);
|
||||
if(err instanceof IpDeniedError)
|
||||
res.status(401);
|
||||
|
||||
else
|
||||
res.status(err.status || 500);
|
||||
|
||||
/* res.render('error', {
|
||||
'message': 'You shall not pass',
|
||||
'error': err
|
||||
});*/
|
||||
|
||||
res.status(403).end();
|
||||
});
|
||||
|
||||
const bouncer = ['phpmyadmin',
|
||||
'phpMyadmin',
|
||||
'phpMyAdmin',
|
||||
@ -183,7 +199,7 @@ function defaultErrorHandler(error, request, response, next) {
|
||||
.render('pages/error');
|
||||
}
|
||||
|
||||
app.get('/feed/:encoded_id', getUrl);
|
||||
app.get('/feed/:encoded_id', cache('15 minutes'), getUrl);
|
||||
|
||||
// Mount 404 handler as penultimate middleware
|
||||
// app.use(notFoundHandler);
|
||||
@ -197,8 +213,6 @@ app.get('*', function(req, res, next) {
|
||||
next(err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
logger.info(`Server listening on port ${port}`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user