added ip filter
This commit is contained in:
parent
5c9c907d61
commit
e17fb1524e
40
server.js
40
server.js
@ -27,9 +27,7 @@ const cache = apicache.middleware;
|
|||||||
|
|
||||||
// app.use(cache('15 minutes'));
|
// app.use(cache('15 minutes'));
|
||||||
|
|
||||||
// const ips = ['212.71.255.44', '82.35.75.161'];
|
const ips = ['212.71.255.44', '82.35.75.161'];
|
||||||
|
|
||||||
const ips = ['212.71.255.44'];
|
|
||||||
|
|
||||||
app.use(ipfilter(ips, { 'mode': 'allow' }));
|
app.use(ipfilter(ips, { 'mode': 'allow' }));
|
||||||
|
|
||||||
@ -177,41 +175,7 @@ function getUrl (req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function notFound(request, response) {
|
app.get('/:encoded_id', cache('15 minutes'), getUrl);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
const server = app.listen(port, () => {
|
const server = app.listen(port, () => {
|
||||||
logger.info(`Server listening on port ${port}`);
|
logger.info(`Server listening on port ${port}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user