|
|
|
@ -83,10 +83,6 @@ wss.on('connection', ws => {
|
|
|
|
|
else if (msg[1].length > 2000) ws.send('error;your url is too long')
|
|
|
|
|
else{
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
console.log(msg[1])
|
|
|
|
|
xhr.timeout = 1000;
|
|
|
|
|
xhr.open('GET', msg[1], true);
|
|
|
|
|
xhr.ontimeout = function(e) {ws.send('error;url timed out')}
|
|
|
|
|
xhr.onreadystatechange = function() {
|
|
|
|
|
if (xhr.readyState === 4) {
|
|
|
|
|
switch(xhr.status) {
|
|
|
|
@ -95,11 +91,8 @@ wss.on('connection', ws => {
|
|
|
|
|
//write to redis
|
|
|
|
|
redis_cli.hmset("surl;"+ran_key, "url", msg[1], "time", Date.now())
|
|
|
|
|
ws.send('surl;'+host+ran_key)
|
|
|
|
|
console.log('key;'+ran_key)
|
|
|
|
|
console.log(ran_key+' --> '+msg[1])
|
|
|
|
|
break;
|
|
|
|
|
case 301: ws.send('error;the url is redirecting (301)');break;
|
|
|
|
|
case 302: ws.send('error;the url is redirecting (302)');break;
|
|
|
|
|
case 303: ws.send('error;the url is redirecting (303)');break;
|
|
|
|
|
case 404: ws.send('error;site does not exist (404)');break;
|
|
|
|
|
case 502: ws.send('error;remote server error (502)');break;
|
|
|
|
|
case 500: ws.send('error;remote server error (500)');break;
|
|
|
|
@ -108,7 +101,11 @@ wss.on('connection', ws => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xhr.open('GET', msg[1], true);
|
|
|
|
|
xhr.timeout = 1000;
|
|
|
|
|
xhr.ontimeout = function(e) {ws.send('error;url is to slow')}
|
|
|
|
|
xhr.send();
|
|
|
|
|
setTimeout(to => {if (xhr.readyState !== 4) ws.send('error;url timed out');xhr.abort()}, 1500)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|