-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
34 lines (29 loc) · 857 Bytes
/
utils.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
var Utils = function() {
this.http = require('http');
this.request = require('request');
};
Utils.prototype.inheritsFrom = function(child, parent) {
child.prototype = Object.create(parent.prototype);
// re-register the constructor
child.prototype.constructor = child;
}
Utils.prototype.httpGet = function(hostname, path, callback_fn) {
var getParams = {
hostname: null,
port: 80,
path: null,
agent: false // create a new agent just for this one request
};
getParams.hostname = hostname;
getParams.path = path;
this.http.get(getParams, function(response) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
callback_fn(body);
});
});
}
module.exports = new Utils();