我正在构建一个节点.js和快速.js Web 应用程序,当发布请求超过 2 分钟时,它无法按预期工作。
发生的情况是,2 分钟后我的express
路由被重新调用,然后,再过 2 分钟(总共 4 分钟(,我在该 post 请求的网络选项卡中收到此错误:
网::ERR_EMPTY_RESPONSE
我读到express
的默认超时设置为 2 分钟,但这仅适用于获取请求......
这是我的路线:
const router = express.Router();
router.post('/', authenticate, async (req, res) => {
console.log('here');
setTimeout(function() {
res.status(201).json({success: true});
}, 400000);
})
当我发出 post 请求时,它会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 周了,任何想法或解决方案都会对我有很大帮助。如果我需要提供更多详细信息,请告诉我。
我通过删除 Web 浏览器的超时来解决我的问题,如下所述: https://github.com/expressjs/express/issues/2174