1
0
Fork 0
peertube/server/core/middlewares/express.ts

19 lines
540 B
TypeScript
Raw Normal View History

2024-06-24 03:10:11 -04:00
import { HttpStatusCode } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
import express from 'express'
export function setReqTimeout (timeoutMs: number) {
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
req.setTimeout(timeoutMs, () => {
logger.error('Express request timeout in ' + req.originalUrl)
return res.fail({
status: HttpStatusCode.REQUEST_TIMEOUT_408,
message: 'Request has timed out.'
})
})
next()
}
}