-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (23 loc) · 729 Bytes
/
server.js
File metadata and controls
27 lines (23 loc) · 729 Bytes
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
const express = require('express');
const server = express();
const port = parseInt(process.env.PORT, 10) || 3000;
const path = require('path');
server.use(express.static('dist'));
server.get("*", (req, res) => {
res.setHeader("Cache-Control", "public, max-age=31556952000");
res.setHeader("Expires", new Date(Date.now() + 31556952000).toUTCString());
switch(true){
case req.url === "/":
res.sendFile(path.join(__dirname + '/dist/index.html'));
return;
default:
res.sendFile(path.join(__dirname + req.url));
break;
}
})
server.listen(port, (err) => {
if (err) {
throw err;
}
console.log(`> Application running on ${port}`);
});