1
內考慮這個不完整的片段:如何使用Node.js的HTTP代理Redis的回調
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);
爲什麼,當我打電話去Redis的客戶端外proxyRequest
get
回調它的工作原理,但是當我移動電話內回調失敗,HTTP請求掛起?
我結束了在你回答了這個幾乎同時搞清楚了這一點。謝謝! – kolrie 2012-04-16 05:55:20
我不明白如何解決這個用例,請你解釋一下嗎? – 2015-07-16 19:39:49