Variable scope in javascript module
    Valentin V. Bartenev 
    vbart at nginx.com
       
    Tue Oct 30 23:56:28 UTC 2018
    
    
  
On Wednesday, 31 October 2018 01:47:49 MSK alweiss wrote:
> My problem is that services can be one, two … ten etc … so not easy to place
> in the callback of the previous subrequest ...
> 
Actually it's not a problem.  Here's an example:
function authorize(r) {
    var n = 0;
    var svcs = ['one', 'two', 'three'];
    var callNextService = function() {
        function done(reply) {
            if (reply.status == 200) {
                r.return(200);
                return;
            }
            callNextService();
        }
        if (n == svcs.length) {
            r.return(403);
            return;
        }
        r.subrequest("/" + svcs[n++], '', done);
    }
    callNextService();
}
  wbr, Valentin V. Bartenev
    
    
More information about the nginx
mailing list