考虑到这个不完整的片段:
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
外部 de redis 客户端get
回调时它可以工作,但是当我在回调中移动调用时它失败并且 HTTP 请求只是挂起?