a little error handling
This commit is contained in:
parent
381d77ac64
commit
dcbcd32e53
12
server.js
12
server.js
@ -29,7 +29,7 @@ const cache = apicache.middleware;
|
|||||||
|
|
||||||
const ips = ['212.71.255.44', '82.35.75.161'];
|
const ips = ['212.71.255.44', '82.35.75.161'];
|
||||||
|
|
||||||
app.use(ipfilter(ips, { 'mode': 'allow' }));
|
// app.use(ipfilter(ips, { 'mode': 'allow' }));
|
||||||
|
|
||||||
app.use((err, req, res, _next) => {
|
app.use((err, req, res, _next) => {
|
||||||
console.log('Error handler', err);
|
console.log('Error handler', err);
|
||||||
@ -124,6 +124,7 @@ function getUrl (req, res) {
|
|||||||
// console.log('Options', options);
|
// console.log('Options', options);
|
||||||
logger.info(`>> getting ${theUrl}`);
|
logger.info(`>> getting ${theUrl}`);
|
||||||
function urlQuery (callback) {
|
function urlQuery (callback) {
|
||||||
|
const httpStart = RegExp('(http|ftp|https):\\/\\/');
|
||||||
try {
|
try {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
http.request(options, responseHandler).end();
|
http.request(options, responseHandler).end();
|
||||||
@ -141,12 +142,21 @@ function getUrl (req, res) {
|
|||||||
|
|
||||||
logger.debug('>> follow', response.headers.location, count);
|
logger.debug('>> follow', response.headers.location, count);
|
||||||
|
|
||||||
|
if (!httpStart.test(response.headers.location)) {
|
||||||
|
//
|
||||||
|
logger.warn('response.headers.location is not a valid url...');
|
||||||
|
logger.info(`Failed to follow for ${theUrl}`);
|
||||||
|
logger.warn(response.headers.location);
|
||||||
|
logger.debug(response.headers);
|
||||||
|
}
|
||||||
|
else {
|
||||||
count++;
|
count++;
|
||||||
if (rUrl.protocol === 'https:')
|
if (rUrl.protocol === 'https:')
|
||||||
https.request(rUrl, responseHandler).end();
|
https.request(rUrl, responseHandler).end();
|
||||||
else
|
else
|
||||||
http.request(rUrl, responseHandler).end();
|
http.request(rUrl, responseHandler).end();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let data = '';
|
let data = '';
|
||||||
response.on('data', chunk => {
|
response.on('data', chunk => {
|
||||||
|
Loading…
Reference in New Issue
Block a user