我正在尝试这样做:
// Setup prox to handle blog requests
httpProxy.createServer({
hostnameOnly: true,
router: {
'http://localhost': '8080',
'http://localhost/blog': '2368'
}
}).listen(8000);在此之前我使用的是:
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});基本上,我还是想用快递...但是,当人们访问http://localhost/blog时,他们会被带到博客上,但仍然会通过port 8080 (最终将是端口80)获得服务。
所以我把它换成了这个,它的效果更好。问题是express接管了路由(据我所知)
var options = {
// pathnameOnly: true,
router: {
'localhost': 'localhost:8080',
'localhost/blog': 'localhost:2368'
}
}
// Setup prox to handle blog requests
var proxyServer = httpProxy.createServer(options);
proxyServer.listen(9000);
require('./app/server/router')(app);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});发布于 2014-03-07 15:30:38
将http-proxy 1.0与express配合使用:
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
app.get("/api/*", function(req, res){
apiProxy.web(req, res, { target: 'http://google.com:80' });
});发布于 2015-09-24 20:16:51
这是一个非常简单的解决方案,使用express-http-proxy可以无缝地与cookies/身份验证配合使用
var proxy = require('express-http-proxy');
var blogProxy = proxy('localhost/blog:2368', {
forwardPath: function (req, res) {
return require('url').parse(req.url).path;
}
});然后简单地说:
app.use("/blog/*", blogProxy);我知道我来晚了,但我希望这能帮助到一些人。
https://stackoverflow.com/questions/20431697
复制相似问题