-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (41 loc) · 1.54 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
50
51
var webpack = require('webpack');
var express = require('express');
var opn = require('opn');
var config = require('./webpack.config.dev');
var proxyMiddleware = require('http-proxy-middleware');
var app = express();
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
quiet: true, // 不显示控制台信息
noInfo: true, // 不显示控制台信息(仅警告和错误)
lazy: false, // 不切换懒惰模式
publicPath: config.output.publicPath,
hot: true, // 是否启用热更新
historyApiFallback: true, // 所有的url路径均跳转到index.html,需要设置为true,否则比如访问localhost:8888,就跳转不到/home页
inline: true, // 是否实时刷新,即代码有更改,自动刷新浏览器
progress: true, // 在控制台输出webpack的编译进度
stats: {
colors: true // 不同类型的信息用不同的颜色显示
},
headers: {
'Access-Control-Allow-Origin': '*'
}
}));
app.use(require('webpack-hot-middleware')(compiler));
// 代理服务器
app.use('/common', proxyMiddleware({
target: 'http://q702-qappdeve-1:802',
changeOrigin: true
}));
//将其他路由,全部返回index.html
app.get('*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
var port = process.env.PORT || 8082;
/* 启动服务 */
app.listen(port, 'localhost', function() {
console.log('成功开启'+ port +'端口');
var uri = 'http://localhost:' + port;
console.log('Listening at ' + uri + '\n');
opn(uri);
});