forked from lux-org/lux-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listen.js
35 lines (31 loc) · 1.04 KB
/
listen.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
var https = require('https');
var fs = require('fs');
const { Stream } = require('stream');
var postHTML = "Listening for Lux Logger..."
var crypto = require('crypto');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
https.createServer(options, function (req, res) {
var body = "";
req.on('data', function (chunk) {
body += chunk;
});
req.on('end', function () {
if (body) {
const { headers } = req;
var id = headers['id'] + req.connection.remoteAddress;
id = crypto.createHash('md5').update(id).digest('hex');
console.log('ID: ' + id);
console.log('BODY: ' + body);
var writeStream = fs.createWriteStream('./logs/' + id + '.json', {flags:'a'});
writeStream.write(body);
}
// TODO: Consider security concerns of following lines
res.writeHead(200, {'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*'});
res.end(postHTML);
});
}).listen(8901);