-
Notifications
You must be signed in to change notification settings - Fork 586
/
server.js
38 lines (30 loc) · 1.03 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
37
38
const compression = require('compression');
const express = require('express');
const https = require('https');
const http = require('http');
const fs = require('fs');
const app = express();
const thirdTour = process.argv[2] == 3;
const forcePort = process.argv[3];
const useHttp = process.argv[4] !== 'https';
const publicFolderName = thirdTour ? 'public3' : 'public';
const port = forcePort ? +forcePort : (thirdTour ? 8443 : 80);
app.set('etag', false);
app.use((req, res, next) => {
res.set('Cache-Control', 'no-store');
next();
});
app.use(compression());
app.use(express.static(publicFolderName));
app.get('/', (req, res) => {
res.sendFile(__dirname + `/${publicFolderName}/index.html`);
});
const server = useHttp ? http : https;
let options = {};
if(!useHttp) {
options.key = fs.readFileSync(__dirname + '/certs/server-key.pem');
options.cert = fs.readFileSync(__dirname + '/certs/server-cert.pem');
}
server.createServer(options, app).listen(port, () => {
console.log('Listening port:', port, 'folder:', publicFolderName);
});