代码之家  ›  专栏  ›  技术社区  ›  p u

节点js延迟响应问题(缓慢的api响应)

  •  -1
  • p u  · 技术社区  · 8 年前

    我有一个 休息API 这需要很多时间 当我的代码在集合的许多字段中搜索时发送响应 我需要在我的客户端(更新的列表)中得到响应 我的问题是,在某个时候,我从我的API得到了一个空白的响应,即 在数据库中搜索前发送响应,结果为空响应

    它确实搜索正确,但由于时间太长,无法正确响应 。如何解决此问题?

    而且,我试着 response.end() at the end 但没用

    2 回复  |  直到 7 年前
        1
  •  0
  •   Sanish Joseph    8 年前

    如果这是默认超时的原因,您可以禁用它。

    var http = require('http');
    var server = http.createServer(function (req, res) {
      res.write('Hi!');
      res.end();
    });
    server.listen(8080);
    console.log(server.timeout);
    server.timeout = 0; //Set to 0 to disable any kind of automatic timeout behavior on incoming connections.
    console.log(server.timeout);
    
        2
  •  0
  •   Prashant Gupta    8 年前

    此代码在60秒后停止响应,server.timeout值以毫秒为单位。

    var server= http.createServer(app).listen(app.get('port'),app.get('host'), function(){
        server.timeout = 60000;
        //console.log(server.timeout);
      });
      console.log("Server listening at http://%s:%s",app.get('host'),app.get('port'));
    }