Questions & Answers

How can I set a timeout for a middleware?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

To set a timeout for a middleware, you can use the timeout() method provided by the httpMiddleware.for() function.

Here's an example of setting a timeout of 5 seconds for a middleware:

import { httpMiddleware } from '@deepkit/http';

// ...

new App({
  // ...
  middlewares: [
    httpMiddleware.for(MyMiddleware).timeout(5000),
  ],
  // ...
}).run();

This sets a timeout of 5 seconds for the execution of the middleware. If the middleware does not call the next() function within the given timeout, Deepkit HTTP will log a warning and proceed with the request handling.