代码之家  ›  专栏  ›  技术社区  ›  Mardare Cristian

如何延长响应超时默认时间?

  •  0
  • Mardare Cristian  · 技术社区  · 7 年前

    我对线程阻塞算法有点问题。

    流程如下: 获取URL>获得Hugesizebuffer>GenerateZIP>UploadZIPToCloud

    我无法使用 express-timeout 单元我也一直在努力打破 .nextTick() 作用

    我甚至尝试查看排队,但我认为这不适用于这种情况。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Taras Danyliuk    7 年前
    // start the server
    const server = app.listen(8080);
    
    // increase the timeout to 4 minutes
    server.timeout = 240000;
    

    这是延长服务器超时的最简单方法,但它会影响一切,而不仅仅是一种方法。

    在您的情况下(您不想只在特定路线上使用它):

    'use strict';
    
    const ms = require('ms');
    const express = require('express');
    const router = express.Router();
    
    router.route('/upload-files')
      .post(
        setConnectionTimeout('12h'),
        require('./actions/upload-files').responseHandler
      );
    
    function setConnectionTimeout(time) {
      var delay = typeof time === 'string'
        ? ms(time)
        : Number(time || 5000);
    
      return function (req, res, next) {
        res.connection.setTimeout(delay);
        next();
      }
    }
    
    exports.router = router;
    

    不是我的代码,在这个thead中找到了: Node Express specific timeout value per route

    你需要更好地搜索:)