-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackingMore.js
More file actions
44 lines (40 loc) · 1.1 KB
/
TrackingMore.js
File metadata and controls
44 lines (40 loc) · 1.1 KB
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
'use strict'
var sentRes = function(url,data,method,fn){
data=data||null;
if(data==null){
var content=require('querystring').stringify(data);
}else{
var content = JSON.stringify(data); //json format
}
var parse_u=require('url').parse(url,true);
var isHttp=parse_u.protocol=='http:';
var options={
host:parse_u.hostname,
port:parse_u.port||(isHttp?80:443),
path:parse_u.path,
method:method,
headers:{
'Content-Type':'application/json',
'Content-Length':Buffer.byteLength(content,"utf8"),
'Trackingmore-Api-Key': process.env.TrackingMore_APIKEY
}
};
var req = require(isHttp?'http':'https').request(options,function(res){
var _data='';
res.on('data', function(chunk){
_data += chunk;
});
res.on('end', function(){
fn!=undefined && fn(_data);
});
});
req.write(content);
req.end();
}
var TrackingMore = {
sentRes: function(url,data,method,fn){
return sentRes(url,data,method,fn);
}
}
//All the variable we want to expose outside needs to be property of "exports" object.
exports.TrackingMore = TrackingMore;