-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (35 loc) · 1022 Bytes
/
server.js
File metadata and controls
43 lines (35 loc) · 1022 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const routes = require('./server/routes');
const webpack = require('webpack');
const config = require('./webpack.config');
const path = require('path');
const app = express();
const port = Number(process.env.PORT) || 3000;
const compiler = webpack(config);
if (NODE_ENV = 'development') {
require('dotenv').config();
}
// Log requests to the console.
app.use(logger('dev'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(bodyParser.json());
app.use(express.static(`${__dirname}/public`));
app.use(bodyParser.urlencoded({ extended: false }));
routes(app);
app.get('/*', (req, res) => {
res.sendFile('index.html', {
root: 'public'
});
});
app.listen(port, (error) => {
if (error) {
throw new Error(error);
}
console.log(`Server running on port ${port} on ${app.get('env')} mode`);
});
module.exports = app;