-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttps-server-base.js
35 lines (31 loc) · 1.01 KB
/
https-server-base.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
// Built-in HTTPS support
const https = require("https");
// Handling GET request (npm install express)
const express = require("express");
// Load of files from the local file system
var fs = require('fs');
const PORT = 4433;
const app = express();
// Get request for resource /
app.get("/", function (req, res) {
console.log(
req.socket.remoteAddress
//+ ' ' + req.socket.getPeerCertificate().subject.CN
+ ' ' + req.method
+ ' ' + req.url);
res.send("<html><body>Secure Hello World with node.js</body></html>");
});
// configure TLS handshake
const options = {
key: fs.readFileSync('secure-server-key-17nov.pem'),
cert: fs.readFileSync('secure-server-17nov.pem>'),
//ca: fs.readFileSync('<server trustbase PEM (root CA)>'),
//requestCert: true,
//rejectUnauthorized: true
};
// Create HTTPS server
https.createServer(options, app).listen(PORT,
function (req, res) {
console.log("Server started at port " + PORT);
}
);