-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathisitup.js
46 lines (46 loc) · 1.31 KB
/
isitup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function() {
var http, isItUp;
http = require("http");
exports.isItUp = isItUp = function(url, callback) {
var opts, request;
opts = {
host: "www.isup.me",
path: "/" + url
};
request = http.request(opts, function(response) {
var data;
data = "";
response.on("data", function(chunk) {
return data += chunk;
});
response.on("end", function() {
var body, down, unknown, up;
body = "";
unknown = data.indexOf('doesn\'t look like a site on the interwho.');
down = data.indexOf('looks down from here.');
up = data.indexOf('is up.');
if (unknown !== -1) {
body = "" + url + " doesn't look like a site on the interwho.";
} else if (down !== -1) {
body = "" + url + " looks down from here.";
} else if (up !== -1) {
body = "" + url + " is up.";
} else {
body = null;
}
if (!body) {
return callback("Could not find the status for " + url);
} else {
return callback(null, body);
}
});
return response.on("error", function(error) {
return callback(error);
});
});
request.on("error", function(error) {
return callback(error);
});
return request.end();
};
}).call(this);