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周因爲我面對這個問題和任何意見或解決方案將幫助我很多。如果我需要提供更多詳細信息,請告訴我。
添加'.catch(ERR =>執行console.log(ERR))'到你的'webAuditsFailures'電話。它可以幫助看到一些錯誤。 –
是否這樣? 'response.catch(err => console.log(err));' – Valip
'webAuditsFailures(req).then((response)=> {...})。catch((err)=> console.log(err ));' –