-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.js
67 lines (46 loc) · 1.59 KB
/
launch.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const https = require('https');
//const http = require('http');
const fs = require('fs');
const options = {
key: fs.readFileSync('testkey.pem'),
cert: fs.readFileSync('test.crt')//cert.pem
};
var port = 54321;
var ip= "127.0.0.1";
require('dns').lookup(require('os').hostname(), function (err, add, fam) {
// console.log('addr: '+add);
ip = add; // if netwerk allows it - Windows Firewall - https://stackoverflow.com/questions/5489956/how-could-others-on-a-local-network-access-my-nodejs-app-while-its-running-on/5490033
console.log("HTTPS server started at https://"+ip+":" + port.toString());
launchServer();
});
function getStream(stream) {
return new Promise(resolve => {
const chunks = [];
stream.on("data", chunk => chunks.push(Buffer.from(chunk)));
stream.on("end", () => resolve(Buffer.concat(chunks).toString()));
});
}
function launchServer(){
https.createServer(options, function (req, res) {
var feedbackUrl = req.url;
if (feedbackUrl.trim() === '/') {
res.writeHead(302, {
location: '/index_simple.html',
});
res.end();
}
else{
fs.readFile(__dirname + feedbackUrl, function (err,data) {//REF:https://stackoverflow.com/questions/16333790/node-js-quick-file-server-static-files-over-http
if (err) {
// res.writeHead(404);
// res.end(JSON.stringify(err));
// return;
res.writeHead(404);
res.end("Nothing to be found here...");
}
res.writeHead(200);
res.end(data);
});
}
}).listen(port,"0.0.0.0");
}