41 lines
1.0 KiB
JavaScript
Executable File
41 lines
1.0 KiB
JavaScript
Executable File
const fs = require('fs');
|
|
const https = require('https');
|
|
const WebSocket = require('ws');
|
|
const url = require('url');
|
|
|
|
const httpsOptions = {
|
|
"enable": true,
|
|
'key': fs.readFileSync('https/localhost.key'),
|
|
'cert': fs.readFileSync('https/localhost.pem'),
|
|
"passphrase": "abcd"
|
|
}
|
|
|
|
server = https.createServer(httpsOptions, (req, res) => {
|
|
let parsedURL = url.parse(req.url, true);
|
|
let path = parsedURL.path.replace(/^\/+|\/+$/g,"");
|
|
if(path == ""){ path = "index.html"; }
|
|
|
|
|
|
let file = __dirname + "/public/" + path;
|
|
|
|
console.log("file : " + file);
|
|
fs.readFile(file, function(err, content){
|
|
if(err){
|
|
console.log("File Not found "+ file);
|
|
res.writeHead(404);
|
|
res.end();
|
|
} else {
|
|
res.setHeader('X-Content-Type-Option', 'nosniff');
|
|
//let mime = lookup(path);
|
|
let mime = "text/html"
|
|
res.writeHead(200,{'Content-type': mime});
|
|
res.end(content);
|
|
}
|
|
})
|
|
});
|
|
|
|
|
|
server.listen(10010);
|
|
console.log("Connect to: https://localhost:10010")
|
|
|