-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (26 loc) · 1002 Bytes
/
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
const express = require('express');
const app = express();
const apiRouter = express.Router();
process.env.PORT = process.env.PORT || 5000;
let staticAssets = null;
// start webpack-dev-server
if(process.env.NODE_ENV !== 'production') {
console.log('starting webpack-dev-server..');
// add some patchwork for the devserver to start!
require('./webpack.middleware')(app);
staticAssets = express.static(__dirname + '/client');
} else if(process.env.NODE_ENV === 'production') {
// serve static assets from the dist folder!
staticAssets = express.static(__dirname + '/dist')
}
// Attach body parser middleware to parse request body
require('./utils/body-parser')(app);
// pass the router around
require('./api/index')(apiRouter);
// attach the router after all the routes have been hatched on to it
app.use('/api', apiRouter);
// start the server
app.use(staticAssets);
app.listen(process.env.PORT, function(){
console.log(`Running on port ${process.env.PORT}`);
});