-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
48 lines (36 loc) · 1 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
48
/**
* Production server
*
* @copyright Copyright (c) 2016, hugw.io
* @author Hugo W - [email protected]
* @license MIT
*/
/* eslint no-console: 0 */
const express = require('express');
const ejs = require('ejs');
const colors = require('colors');
const compression = require('compression');
// Define base dir path
const dir = process.cwd();
// Define default port
const port = process.env.PORT || 5000;
// Create Express instance
const app = express();
// Compress all requests using gzip
app.use(compression());
// Set default server port
app.set('port', port);
// Set default server views path
app.set('views', `${dir}/dist`);
// Serve ./dist as a static folder
app.use(express.static(`${dir}/dist`, { index: false }));
// Set template ./views engine
app.engine('html', ejs.renderFile);
// Route all requests to index.html
app.get('*', (req, res) => {
res.render('index.html');
});
// Boot Server
app.listen(app.get('port'), () => {
console.log(colors.green(`App running on http://localhost:${port}`));
});