-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (24 loc) · 980 Bytes
/
app.js
File metadata and controls
28 lines (24 loc) · 980 Bytes
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
var static = require('node-static');
var https = require('https');
const fs = require('fs');
var fileServer = new static.Server('./public');
const options = {
key: fs.readFileSync('localhost.key'),
cert: fs.readFileSync('localhost.crt')
};
https.createServer(options, function (request, response) {
request.addListener('end', function () {
console.log(request.url);
console.log(request.httpVersion);
console.log(JSON.stringify(request.headers));
fileServer.serve(request, response, function (err, result) {
console.log("Serving " + request.url);
if (err) { // There was an error serving the file
console.error("Error serving " + request.url + " - " + err.message);
// Respond to the client
response.writeHead(err.status, err.headers);
response.end();
}
});
}).resume();
}).listen(3000);