forked from wevote/WebApp
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
34 lines (31 loc) · 1.25 KB
/
Copy pathserver.js
File metadata and controls
34 lines (31 loc) · 1.25 KB
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
/* eslint-disable */
// start the express server
constexpress=require("express");
constapp=express();
constfs=require("fs");
consthttps=require("https");
constpath=require("path");
constwebAppConfig=require("./src/js/config");
module.exports=function(PROD){
constport=3000;// PROD ? 3000 : 3003;
constopts={redirect: true};
consthostname=PROD ? webAppConfig.WE_VOTE_HOSTNAME : "localhost";
constsecureCertificateInstalled=webAppConfig.SECURE_CERTIFICATE_INSTALLED||false;
app.use("/",express.static("build",opts));
app.all("*",(req,res)=>res.sendFile(__dirname+"/build/index.html"));
if(secureCertificateInstalled){
constcertOptions={
key: fs.readFileSync(path.resolve(__dirname+"/src/cert/server.key")),
cert: fs.readFileSync(path.resolve(__dirname+"/src/cert/server.crt")),
};
constserver=https.createServer(certOptions,app).listen(port,function(){
console.log("INFO: https server started",newDate());
console.log(`INFO: Server is at https://${hostname}:${port}`);
});
}else{
app.listen(port,()=>{
console.log("INFO: express server started",newDate());
console.log(`INFO: Server is at http://${hostname}:${port}`);
});
}
};