-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (47 loc) · 1.42 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
52
53
54
55
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
// 当修改时,让 webpack 自动刷新页面
for (entryPoint in config.entry) {
config.entry[entryPoint].unshift("webpack-dev-server/client?http://localhost:9090", "webpack/hot/dev-server");
}
config.plugins.push(new webpack.HotModuleReplacementPlugin());
config.devtool = 'eval';
var rewriteUrl = function(replacePath) {
return function(req, opt) { // gets called with request and proxy object
var queryIndex = req.url.indexOf('?');
var query = queryIndex >= 0 ? req.url.substr(queryIndex) : "";
req.url = req.path.replace(opt.path, replacePath) + query;
console.log("rewriting ", req.originalUrl, req.url, req.hostname);
}
}
var prod = true;
var target;
if (prod) {
target = "https://api.quzhiboapp.com";
} else {
target = "http://localhost:3005";
}
var proxy = [{
path: new RegExp("/api/(.*)"),
target: target,
rewrite: rewriteUrl("/$1"),
changeOrigin: true
}]
var app = new WebpackDevServer(webpack(config), {
// allow access over local network
host: '0.0.0.0',
publicPath: config.output.publicPath,
historyApiFallback: true,
proxy: proxy,
hot: true,
debug: true,
// suppress useless text
noInfo: true
})
app.listen(9090, '0.0.0.0', function (err, result) {
console.log('http://localhost:9090');
if (err) {
console.log(err);
}
})