nodejs http-proxy不转发put请求

问题描述 投票:3回答:1

我使用http-proxy创建了代理并表达了中间件。 但是,它不会转发PUT请求 - 这对我所代理的应用程序至关重要。 我究竟做错了什么?

(代理服务器的目的是为代理后面的应用程序提供身份验证。如果还有其他方法可以做到这一点,我将不胜感激。)

var proxy = new httpProxy.RoutingProxy();
var app = express();

app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.engine('ejs', require('ejs-locals'));
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({secret: 'rupert'}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(function(req, res) {
proxy.proxyRequest(req, res, {
  host: 'localhost',
  port: 8080
});
});
app.use(express.static(__dirname + '/../../public'));
});

app.get('/login', function(req, res){
  res.render('login', { user: req.user, message: req.flash('error') });
});

app.post('/login', 
  passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
  function(req, res) {
  res.redirect('/');
});

app.get('/logout', function(req, res){
  req.logout();
  res.redirect('/')
});

app.all('/*', function(req, res, next) {
  return next();
});

app.listen(3000,'localhost');
node.js express http-proxy
1个回答
0
投票

您可以尝试使用http-proxy的缓冲区功能,如下所示: https//github.com/nodejitsu/node-http-proxy/issues/180

或者,可能存在向请求对象表达非标准事物的问题:请参阅https://github.com/nodejitsu/node-http-proxy/issues/153上的问题#153

特别是马拉克的回应:“这是一个明确的问题。

Connect / Express中间件正在为您的响应对象执行非标准操作,中断流式传输。 尝试使用原始请求模块而不是http-proxy。

如果您需要适当的中间件堆栈,请查看https://github.com/flatiron/union

不知道联盟是否会解决这个问题,但似乎明确表示更改了http-proxy可以处理的请求。

© www.soinside.com 2019 - 2024. All rights reserved.