-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathhttps.js
More file actions
31 lines (27 loc) · 730 Bytes
/
https.js
File metadata and controls
31 lines (27 loc) · 730 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
29
30
31
// HTTPS module
const https = require("https");
// File system module.
const fs = require("fs");
// Authentication module.
const auth = require("../src/http-auth");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
});
// HTTPS server options.
const options = {
key: fs.readFileSync(__dirname + "/../data/server.key"),
cert: fs.readFileSync(__dirname + "/../data/server.crt")
};
// Starting server.
https
.createServer(
options,
basic.check((req, res) => {
res.end(`Welcome to private area - ${req.user}!`);
})
)
.listen(1337, () => {
// Log URL.
console.log("Server running at https://127.0.0.1:1337/");
});