-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_hot.js
54 lines (51 loc) · 1.25 KB
/
server_hot.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
50
51
52
53
54
var webpack = require('webpack');
var express = require('express');
var config = require('./webpack.config.hot');
var dataJson = require('./dataJson.json');
var app = express();
var compiler = webpack(config);
var bodyParser = require('body-parser');
var bs = require('browser-sync').create();
// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({ extended: true });
app.use(bodyParser());
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
inline: true,
progress: true,
stats: {
colors: true
}
}));
app.use(require('webpack-hot-middleware')(compiler));
/**获取初始数据
* post: 请求
* url: http://127.0.0.1:8088/getData
*/
app.post('/getData',bodyParser.json() ,function(req,res){
console.log(req.body);
var resData = {
err:0,
data:dataJson
};
res.end(JSON.stringify(resData));
});
/**
* 将其他路由,全部返回index.html
*/
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
app.listen(8088, function() {
console.log('正常打开8088端口');
bs.init({
open: false,
ui: false,
notify: false,
proxy: 'localhost:8088',
files: ['./src/index.html'],
port: 8088
});
});