NestJS REST API times out for long running request

爷,独闯天下 提交于 2021-01-28 02:12:45

问题


After lengthy investigations the problems seems to be that the long running request times out and the endpoint is called again in NodeJS. There is no new network request from browser. I made a few tests and after 2 mins the endpoint is invoked again. I read that the default timeout for the http requests in NodeJS in 2mins.

https://nodejs.org/docs/latest-v12.x/api/http.html#http_server_timeout

I am using NestJS (with express), does anyone know how to increase this timeout value using NestJS framework ?

Here is my initial question: Angular 9 http call with nestjs backend

-Jani


回答1:


this seems to do the trick per request. I don't know how to do it on server level but this is enough for me.

req.setTimeout(300000); // 5 minutes



回答2:


You can use some packages to apply a timeout as a middleware. https://www.npmjs.com/package/@nest-middlewares/connect-timeout

This package is just a wrapper of an express middleware, so be sure you use the express platform on your project.



来源:https://stackoverflow.com/questions/60787515/nestjs-rest-api-times-out-for-long-running-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!