0

I'm using NodeJS Express

I have set a maximum request timeout of 25 seconds. When the timer exceeds the 25 seconds It needs to send a response (status 500). At this moment I'm getting errors that the connection is closed without a response, how can I improve my code?

Note: the request timeout could just be an image, I still want full the page to load, only without that particular image (request).

Below you can find the code I'm currently using

const haltOnTimedout = (req, res, next) => {
  if (!req.timedout) {
    next();
  }else {
    res.status(500)
  }
}

app.use(timeout('25s'))
app.use(bodyParser.json({ extended: true }))
app.use(haltOnTimedout)
jamep37912
  • 27
  • 4
  • Where does `timeout` middleware come from? What error did you get? – Lin Du May 17 '21 at 07:47
  • i hope this will help you : https://stackoverflow.com/questions/40128614/how-to-customise-time-out-response-using-express-and-connect-timeout – mimi May 17 '21 at 07:50

0 Answers0