2017-08-25 132 views
3

我构建了一个node.js和express.js web应用程序,并且在发布请求花费的时间超过2分钟时,它无法按预期工作。
什么情况是,2分钟后,我的express路由重叫,然后,再过2分钟后(4分钟共)我得到了这个职位要求的网络选项卡此错误:快速发布请求给出ERR_EMPTY_RESPONSE

网: :ERR_EMPTY_RESPONSE

,我读了express有一个默认的超时时间设置为2分钟,但只适用于get请求...

这是我的路线:

const router = express.Router(); 

router.post('/', authenticate, async (req, res) => { 
    console.log('here'); 
    setTimeout(function() { 
    res.status(201).json({success: true}); 
    }, 400000); 
}) 

它发出here当我发出发布请求时,然后在2分钟后再次打印here

这是我从服务器index文件:

const app = express(); 

app.use(bodyParser.json({limit: '50mb'})); 
const compiler = webpack(webpackConfig); 

app.use(webpackMiddleware(compiler, { 
    hot: true, 
    publicPath: webpackConfig.output.publicPath, 
    noInfo: true 
})); 
app.use(webpackHotMiddleware(compiler)); 

app.get('/*', (req, res) => { 
    res.sendFile(path.join(__dirname, './index.html')); 
}); 

app.listen(3000,() => console.log('Running on localhost:3000')); 
app.timeout = 700000; 

已经有2周因为我面对这个问题和任何意见或解决方案将帮助我很多。如果我需要提供更多详细信息,请告诉我。

+0

添加'.catch(ERR =>执行console.log(ERR))'到你的'webAuditsFailures'电话。它可以帮助看到一些错误。 –

+0

是否这样? 'response.catch(err => console.log(err));' – Valip

+1

'webAuditsFailures(req).then((response)=> {...})。catch((err)=> console.log(err ));' –

回答