2012-04-16 2 views
1

Vu cet extrait incomplet:Utilisation du proxy http Node.js dans un rappel 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); 

Pourquoi est-ce que quand je l'appelle proxyRequest en dehors de Redis client get callback cela fonctionne, mais quand je passe l'appel à l'intérieur le rappel échoue et la requête HTTP se bloque simplement?

Répondre