在Rediscallback中使用node.js http代理

考虑到这个不完整的片段:

var util = require('util'), nconf = require('nconf'), http = require('http'), httpProxy = require('http-proxy'), express = require('express'), repoServer = express.createServer(), redis = require('redis'), redisClient = redis.createClient(); // (...) var proxy = new httpProxy.RoutingProxy(); http.createServer(function (req, res) { console.log("URL", req.url); if (req.url) { var token = req.url.split("/")[1]; // if I leave this code here it works fine // var target = { host: 'local-01', port: 8024 } // proxy.proxyRequest(req, res, target); // now I need to retrieve some routing information // from redis, so I query redis here redisClient.get(token, function (err, reply) { // if I leave this code here the request hangs var target = { host: 'local-01', port: 8024 } proxy.proxyRequest(req, res, target); }); } }).listen(routerInfo.port, routerInfo.address); 

为什么当我在proxyRequest客户端外面调用proxyRequest getcallback的时候,它的工作原理是什么,但是当我在callback中移动它的调用时,它会失败,并且HTTP请求会挂起?

请求是stream,也许你想缓冲

请参阅: https : //github.com/nodejitsu/node-http-proxy/blob/master/examples/http/latent-proxy.js