Considering this incomplete snippet:
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);
Why is it that when I call the proxyRequest
outside de redis client get
callback it works , but when I move the call inside the callback it fails and the HTTP request just hangs?
request is stream, maybe you want to buffer
see: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/latent-proxy.js