-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (35 loc) · 1.21 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
41
42
43
44
45
46
47
/**
* Creates a server instance of the front-end application.
* Used in review, staging and production instances primarily.
*
* On local development are usually webpack-dev-server used
*/
/* eslint-disable comma-dangle */
const express = require('express');
const path = require('path');
const helmet = require('helmet');
const logger = require('morgan');
const app = express();
app.use(helmet());
app.use(logger('common'));
const staticDir = path.resolve(__dirname, 'dist');
console.info(`Serving files from ${staticDir}`);
app.use('/static', express.static(path.join(staticDir, 'static'), {
maxAge: '2 days'
}));
// Ensure this is placed before /public static-dir
app.use('/public/favicon.ico', (req, res) => {
res.sendFile(path.join(staticDir, 'favicon.ico'));
});
app.use('/favicon.ico', (req, res) => {
res.sendFile(path.join(staticDir, 'favicon.ico'));
});
app.use('/public', express.static(path.join(staticDir, 'public')));
// Always send the same file, so that our router can handle the routing.
app.get('*', (req, res) => {
res.sendFile(path.join(staticDir, 'index.html'));
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Running app at http://127.0.0.1:${port}`);
});