changed the url to /feed/ and reject everything else

This commit is contained in:
Martin Donnelly 2018-06-13 22:14:28 +01:00
parent 636a02d04d
commit 0a587fb804

View File

@ -88,7 +88,7 @@ function getUrl (req, res) {
if (theUrl === undefined || bouncer.indexOf(theUrl) !== -1 || theUrl === '') {
logger.warn(`You're not getting in ${theUrl}`);
res.status(400).send('');
return;
}
@ -119,9 +119,9 @@ function getUrl (req, res) {
logger.debug('>> follow', response.headers.location, count);
count++;
if (rUrl.protocol === 'https:')
if (rUrl.protocol === 'https:')
https.request(rUrl, responseHandler).end();
else
else
http.request(rUrl, responseHandler).end();
}
@ -130,7 +130,7 @@ function getUrl (req, res) {
data += chunk;
});
response.on('end', () => {
if (response.statusCode !== 302 && response.statusCode !== 301)
if (response.statusCode !== 302 && response.statusCode !== 301)
callback(data);
});
response.on('error', e => {
@ -151,7 +151,35 @@ function getUrl (req, res) {
});
}
app.get('/:encoded_id', getUrl);
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', getUrl);
// Mount 404 handler as penultimate middleware
// app.use(notFoundHandler);
// Final middleware is our catch-all error handler
app.use(defaultErrorHandler);
const server = app.listen(port, () => {
logger.info(`Server listening on port ${port}`);