-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·50 lines (44 loc) · 1.06 KB
/
app.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
47
48
49
50
#!/usr/bin/env node
var http = require('http');
var https = require('https');
var url = require('url');
var querystring = require('querystring');
var config = require('./config');
var mailman9 = require('./mailman9');
var interfaceUrl = url.parse(config.url);
if (!interfaceUrl.port) {
if (interfaceUrl.protocol == 'http:') {
interfaceUrl.port = 80;
} else {
interfaceUrl.port = 443;
}
}
if (interfaceUrl.protocol == 'https:') {
http = https;
}
var contents = querystring.stringify({
interfaceSecret: config.interfaceSecret,
});
var options = {
host: interfaceUrl.hostname,
port: interfaceUrl.port,
path: interfaceUrl.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length' : contents.length
}
};
var req = http.request(options, function (res) {
var buffer = '';
res.setEncoding('utf8');
res.on('data', function (data) {
buffer += data;
});
res.on('end', function () {
var data = JSON.parse(buffer);
mailman9.emit('data', data);
});
});
req.write(contents);
req.end();