-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
34 lines (29 loc) · 1023 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
//--========================================================================--
//-- 本地代理服务器
//-- loke 2018-02-26 09:35:56
//--========================================================================--
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config.dev');
// 相当于通过本地node服务代理请求到了http://**.**.**.**/api
var proxy = {
'/api': {
target: 'http://192.168.1.58:1111',//'http://192.168.1.208:8070',
pathRewrite: {'^/api': '/web/api'},
changeOrigin: true
},
};
//启动服务
var server = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
disableHostCheck: true, //开启后其他机器才可以访问到本地
proxy: proxy,
stats: {
colors: true
},
});
//将其他路由,全部返回index.html
server.app.get('*', function (req, res) {
res.sendFile(__dirname + '/index.html')
});
server.listen(3000);