0

I have a question about the code below: I would need a confirmation that all the processing done in proxyRes event will be done asynchronously and all processing time in it won't affect the proxying time.

Thank you in advance for help in this

    var server = http.createServer(function (req, res) {
    console.time();
    var proxy = httpProxy.createProxyServer();
    proxy.web(req, res, {
      target: 'https://gdev.sserver.be/api/host1/account',
    });
    console.timeEnd();

    proxy.on('proxyRes', function (proxyRes, req, res) {
        //console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
        proxyRes.on('data', function (chunk) {
                console.log('resp => ' + chunk);
                connection.query('INSERT INTO test SET ?', {content: chunk}, function(err, result) {
                        if (err) throw err;
                        console.log('writing in db');
                });
        });
        proxy.close();
        proxy = null;
    });
}).listen(3000);
Alessandro
  • 1
  • 1
  • 3

1 Answers1

0

Yes, the contents of your proxyRes handler appear to be asynchronous. The proxy will occur while the database query is still doing what it needs to do, so you're right that it won't affect proxying time.

CatDadCode
  • 58,507
  • 61
  • 212
  • 318