No response after accessing database in jugglingdb

I am trying to use my application.js application as a (transparent) proxy. When a user tries to request an external website, the application will check if the user with this ip address has been authenticated before.

If so, an external site will be shown; if not, the user will be prompted to log in. The problem is that the response is not processed when there is access to the user database object. When I comment out a section of a database and just use the code inside an anonymous function, the program works as expected.

action('exturl', function () { User.all({ where: { ipaddress: req.ip }}, function(err, users) { if (users.length > 0) { this.user = user[0]; var proxy = http.createClient(80, req.headers['host']) var proxy_request = proxy.request(req.method, req.url, req.headers); proxy_request.addListener('response', function (proxy_response) { proxy_response.addListener('data', function(chunk) { res.write(chunk, 'binary'); }); proxy_response.addListener('end', function() { res.end(); }); res.writeHead(proxy_response.statusCode, proxy_response.headers); }); req.addListener('data', function(chunk) { proxy_request.write(chunk, 'binary'); }); req.addListener('end', function() { proxy_request.end(); }); } else { redirect(path_to.login); } }); }); 

Is there a glitch inside my code? I do not know what I am doing wrong.

+4
source share

All Articles