-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (26 loc) · 1.03 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
const __DEVELOPMENT__ = process.env.NODE_ENV === 'development';
const config = require('./config/config.json');
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const api = require('./routes/api');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(`${__dirname}/build`));
if (__DEVELOPMENT__) {
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.dev');
const compiler = webpack(webpackConfig);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
}
app.use('/api', api);
app.get('/markup', (req, res) => res.sendFile(`${__dirname}/build/index2.html`));
app.get('/*', (req, res) => res.sendFile(`${__dirname}/build/index.html`));
app.listen(config.port, () => {
console.log(`listening on *: ${config.port}`);
});