我目前像这样代理我的开发机器:
bs.init({
proxy: "http://localtest.me:80",
port: 81,
open: true,
notify: false
});
我需要将所有子域请求路由到同一服务器:子域完整的端口。我今天如何使用 http-proxy-middleware 来做到这一点?以下内容不起作用(根据BrowserSync:Proxy Subdomains 11 个月前)...
const proxy = require('http-proxy-middleware');
const bs = require('browser-sync').create();
bs.init({
proxy: {
middleware: [
function (req, res, next) {
let target = 'http://' + req.headers.host.replace('localtest.me:81', 'localtest.me:80');
proxy({
target,
changeOrigin: true
})(req, res, next);
}
]
,rewriteRules: [
{
match: /localtest.me:80/g,
fn: function (req, res, match) {
return 'localtest.me:81';
}
}
]
},
open: true,
notify: false
});