1
0
Fork 0
peertube/server/core/middlewares/express.ts
2024-06-24 09:10:11 +02:00

18 lines
540 B
TypeScript

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()
}
}