forked from jaylone/redux-saga-shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (41 loc) · 1.12 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
49
var path = require('path');
var webpack = require('webpack');
var express = require('express');
var config = require('./webpack.dev.config');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
var app = express();
var compiler = webpack(config);
const serverOptions = {
contentBase: config.src,
quiet: false,
noInfo: false,
hot: true,
inline: true,
lazy: false,
publicPath: config.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
stats: { colors: true },
};
app.use(webpackDevMiddleware(compiler, serverOptions));
app.use(webpackHotMiddleware(compiler));
app.get('/api', function(req, res) {
var data = {
ret: true,
msg: 'success',
data: {
list: ['The', 'result', 'come', 'from', 'server.']
}
};
res.statusCode = 200;
res.end(JSON.stringify(data));
});
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, './example/index.html'));
});
app.listen(3000, function(err) {
if (err) {
return console.error(err);
}
console.log('Listening at http://localhost:3000/');
})