-
Notifications
You must be signed in to change notification settings - Fork 2
/
listen.js
36 lines (31 loc) · 1.1 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('/data/risecamp/pki/tls/private/freddie.millennium.berkeley.edu.key'),
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 = crypto.createHash('md5').update(req.connection.remoteAddress).digest('hex');
id = id + headers['id']
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);