forked from sagardere/set-up-SSL-in-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
33 lines (26 loc) · 807 Bytes
/
index.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
const express = require('express');
const http = require('http');
const https = require('https');
const fs = require('fs');
const httpPort = 3000;
const httpsPort = 5000;
app = express()
var key = fs.readFileSync(__dirname + '/certsFiles/selfsigned.key');
var cert = fs.readFileSync(__dirname + '/certsFiles/selfsigned.crt');
var credentials = {
key: key,
cert: cert
};
//GET home route
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.send('Hello World.');
});
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(httpPort, () => {
console.log("Http server listing on port : " + httpPort)
});
httpsServer.listen(httpsPort, () => {
console.log("Https server listing on port : " + httpsPort)
});