-
Notifications
You must be signed in to change notification settings - Fork 44
/
test.js
47 lines (40 loc) · 1.1 KB
/
test.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
const http = require('http');
const postData = JSON.stringify({
"serverKey": "NodeListServerDefaultKey",
});
const options = {
hostname: 'spotty-frogs-watch.loca.lt',
port: 80,
path: '/list',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData),
},
};
const req = http.request(options, (res) => {
//console.log(`STATUS: ${res.statusCode}`);
//console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
content = chunk;
});
res.on('end', () => {
req.write(postData);
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
// Write data to request body
req.write(postData);
this.httpServer = http.createServer(function(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.writeHead(200);
res.end(content);
}.bind(this));
this.httpServer.listen(8082, function() {
// Stats server
console.log("* \u001B[33mLoaded stats server on port " + 8082 + "\u001B[0m");
}.bind(this));