-
Notifications
You must be signed in to change notification settings - Fork 57
/
server.js
36 lines (30 loc) · 1.26 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-disable import/no-extraneous-dependencies */
const finalhandler = require('finalhandler');
const http = require('http');
const https = require('https');
const serveStatic = require('serve-static');
const fs = require('fs');
const serve = serveStatic('./');
const HTTP_PORT = 3001;
const HTTPS_PORT = 8082;
const httpServer = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res));
});
httpServer.listen(HTTP_PORT);
console.log(`HTTP server instance running @ ${HTTP_PORT}`);
fs.stat('certificates/server.key', (err) => {
if (err == null) {
const options = {
key: fs.readFileSync('certificates/server.key'),
cert: fs.readFileSync('certificates/server.crt'),
};
const httpsServer = https.createServer(options, (req, res) => {
serve(req, res, finalhandler(req, res));
});
httpsServer.listen(HTTPS_PORT);
console.warn('\nNOTE: Running HTTP server has been removed as getUserMedia() has been deprecated for HTTP on Chrome 42 and above. Please run demo on HTTPS as recommended\n\n-\n');
console.log(`HTTPS server instance running @ ${HTTPS_PORT}`);
} else {
console.warn(`HTTPS server instance failed to start as certificate failed to load. Error (for certificates/server.key): ${err.code}`);
}
});