a little error handling
This commit is contained in:
parent
dcbcd32e53
commit
77e19f3e06
40
server.js
40
server.js
@ -105,6 +105,8 @@ const bouncer = ['phpmyadmin',
|
||||
'phpmyadmin2018',
|
||||
'phpmanager'];
|
||||
|
||||
const httpStart = RegExp('(http|ftp|https):\\/\\/');
|
||||
|
||||
function getUrl (req, res) {
|
||||
const theUrl = req.params.encoded_id;
|
||||
logger.debug('Want', theUrl);
|
||||
@ -124,7 +126,6 @@ function getUrl (req, res) {
|
||||
// console.log('Options', options);
|
||||
logger.info(`>> getting ${theUrl}`);
|
||||
function urlQuery (callback) {
|
||||
const httpStart = RegExp('(http|ftp|https):\\/\\/');
|
||||
try {
|
||||
let count = 0;
|
||||
http.request(options, responseHandler).end();
|
||||
@ -133,29 +134,32 @@ function getUrl (req, res) {
|
||||
response.setEncoding('utf8');
|
||||
if (response.statusCode === 302 || response.statusCode === 301) {
|
||||
body = [];
|
||||
const rUrl = URL.parse(response.headers.location);
|
||||
logger.debug('>> follow', response.headers.location, count);
|
||||
let rUrl;
|
||||
|
||||
if (!httpStart.test(response.headers.location)) {
|
||||
//
|
||||
logger.warn('response.headers.location is not a valid url...');
|
||||
logger.info(`Trying to fix for ${theUrl}`);
|
||||
logger.warn(response.headers.location);
|
||||
logger.debug(response.headers);
|
||||
|
||||
const tempUrl = new URL(theUrl);
|
||||
rUrl = URL.parse(`${tempUrl.origin}${response.headers.location}`);
|
||||
}
|
||||
else
|
||||
rUrl = URL.parse(response.headers.location);
|
||||
|
||||
rUrl.followAllRedirects = true;
|
||||
rUrl.headers = {
|
||||
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
|
||||
};
|
||||
|
||||
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++;
|
||||
if (rUrl.protocol === 'https:')
|
||||
https.request(rUrl, responseHandler).end();
|
||||
else
|
||||
http.request(rUrl, responseHandler).end();
|
||||
}
|
||||
count++;
|
||||
if (rUrl.protocol === 'https:')
|
||||
https.request(rUrl, responseHandler).end();
|
||||
else
|
||||
http.request(rUrl, responseHandler).end();
|
||||
}
|
||||
|
||||
let data = '';
|
||||
|
Loading…
Reference in New Issue
Block a user