added ip filter

This commit is contained in:
Martin Donnelly 2018-06-13 23:14:25 +01:00
parent 5c9c907d61
commit e17fb1524e

View File

@ -27,9 +27,7 @@ const cache = apicache.middleware;
// app.use(cache('15 minutes'));
// const ips = ['212.71.255.44', '82.35.75.161'];
const ips = ['212.71.255.44'];
const ips = ['212.71.255.44', '82.35.75.161'];
app.use(ipfilter(ips, { 'mode': 'allow' }));
@ -177,41 +175,7 @@ function getUrl (req, res) {
});
}
function notFound(request, response) {
logger.warn(
'Unhandled resource',
{
'statusCode': 404,
'error': 'Unknown resource',
'resource': request.originalUrl
}
);
return response
.status(404);
}
function defaultErrorHandler(error, request, response, next) {
logger.error('Uncaught error', { 'statusCode': 500, error });
return response
.status(500)
.render('pages/error');
}
app.get('/feed/:encoded_id', cache('15 minutes'), getUrl);
// Mount 404 handler as penultimate middleware
// app.use(notFoundHandler);
// Final middleware is our catch-all error handler
app.get('*', function(req, res, next) {
log.info(req);
const err = new Error(`${req.ip} tried to access /Forbidden`);
// Sets error message, includes the requester's ip address!
err.statusCode = 403;
next(err);
});
app.get('/:encoded_id', cache('15 minutes'), getUrl);
const server = app.listen(port, () => {
logger.info(`Server listening on port ${port}`);