-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (34 loc) · 879 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
34
35
36
37
38
39
40
41
42
43
const http2 = require('spdy');
const http1_1 = require('http');
const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');
app.use('/', express.static(path.join(__dirname, '/dist')));
app.get('/', (req, res) => {
res.sendFile('dist/index.html', { root: __dirname });
});
const options = {
key: fs.readFileSync('./server.key'),
cert: fs.readFileSync('./server.crt')
}
const HTTPS_PORT = 443;
const log = port => {
const ending = port === HTTPS ? 's' : '';
return `
server is listening on http${ending}://localhost:${port}.
You can open the URL in the browser.`
};
http2
.createServer(options, app)
.listen(HTTPS, () => {
console.log(log(HTTPS));
}
)
const HTTP_PORT = 80;
http1_1
.createServer(app)
.listen(HTTP, () => {
console.log(log(HTTP));
}
)