-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
40 lines (37 loc) · 1.41 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
39
40
/* eslint-disable */
// start the express server
const compression = require('compression')
const express = require("express");
const app = express();
const fs = require("fs");
const https = require("https");
const path = require("path");
const webAppConfig = require("./src/js/config");
module.exports = function (PROD) {
if (PROD === undefined) {
PROD = 0;
}
console.log("INFO: top of script", new Date());
const port = 3000; // PROD ? 3000 : 3003;
const opts = { redirect: true };
const hostname = PROD ? webAppConfig.WE_VOTE_HOSTNAME : "localhost";
const secureCertificateInstalled = webAppConfig.SECURE_CERTIFICATE_INSTALLED || false;
app.use(compression())
app.use("/", express.static("build", opts));
app.all("*", (req, res) => res.sendFile(__dirname + "/build/index.html"));
if (secureCertificateInstalled) {
const certOptions = {
key: fs.readFileSync(path.resolve(__dirname + "/src/cert/server.key")),
cert: fs.readFileSync(path.resolve(__dirname + "/src/cert/server.crt")),
};
const server = https.createServer(certOptions, app).listen(port, function () {
console.log("INFO: https server started", new Date());
console.log(`INFO: Server is at https://${hostname}:${port}`);
});
} else {
app.listen(port, () => {
console.log("INFO: express server started", new Date());
console.log(`INFO: Server is at http://${hostname}:${port}`);
});
}
};