Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js nodejs代理计时和异步行为_Node.js_Asynchronous_Http Proxy_Node Http Proxy - Fatal编程技术网

Node.js nodejs代理计时和异步行为

Node.js nodejs代理计时和异步行为,node.js,asynchronous,http-proxy,node-http-proxy,Node.js,Asynchronous,Http Proxy,Node Http Proxy,我对下面的代码有一个问题: 我需要确认所有处理都在proxyRes事件中完成 将异步完成,并且其中的所有处理时间不会影响 代理时间 在此提前感谢您的帮助 var server = http.createServer(function (req, res) { console.time(); var proxy = httpProxy.createProxyServer(); proxy.web(req, res, { target: 'https://

我对下面的代码有一个问题: 我需要确认所有处理都在proxyRes事件中完成 将异步完成,并且其中的所有处理时间不会影响 代理时间

在此提前感谢您的帮助

    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);

是的,proxyRes处理程序的内容似乎是异步的。代理将在数据库查询仍在执行其需要执行的操作时发生,因此您是对的,它不会影响代理时间。

我的回答有帮助吗?