-
Notifications
You must be signed in to change notification settings - Fork 98
/
server.js
24 lines (22 loc) · 896 Bytes
/
server.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
const { hostname } = require('os');
const https = require('https');
const fs = require('fs');
const STACK_NAME = process.env.STACK_NAME || "Unknown Stack";
const httpsPort = 8443;
const httpsKey = '../keys/key.pem'
const httpsCert = '../keys/cert.pem'
if (fs.existsSync(httpsKey) && fs.existsSync(httpsCert)) {
console.log('Starting https server')
const message = `Hello HTTPS World from ${hostname()} in ${STACK_NAME}\n`;
const options = { key: fs.readFileSync(httpsKey), cert: fs.readFileSync(httpsCert) };
const server = https.createServer(options, (req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(message);
});
server.listen(httpsPort, hostname, () => {
console.log(`Server running at http://${hostname()}:${httpsPort}/`);
});
} else {
console.log('Could not find certificate/key')
}