-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.js
36 lines (31 loc) · 931 Bytes
/
module.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
var request = require("request");
var http = require('http');
function expand(shortUrl, options, callback) {
// options are optional, the function can still be used like this: expand(shortUrl, callback)
if(typeof options == 'function') {
callback = options;
options = {};
}
var defaultOptions = {
method: "HEAD"
, url: shortUrl
, followAllRedirects: true
, timeout: 10000
, pool: pool
};
// merge the user-supplied options with the default options
for(var attribute in options) {
defaultOptions[attribute] = options[attribute];
}
var pool = new http.Agent({'maxSockets': Infinity});
request(defaultOptions, function (error, response) {
if (error) {
callback(error);
} else {
callback(undefined, response.request.href);
}
}).setMaxListeners(0);
}
module.exports = {
expand: expand
}