mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
b298456126
* Initial plan * Add 30-minute timeout for files.create endpoint to handle large file uploads Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
26 lines
749 B
TypeScript
26 lines
749 B
TypeScript
import type { Next } from "koa";
|
|
import type { AppContext } from "@server/types";
|
|
|
|
/**
|
|
* Middleware to extend the request timeout for specific routes.
|
|
*
|
|
* @param timeoutMs The timeout in milliseconds.
|
|
* @returns The middleware function.
|
|
*/
|
|
export default function timeout(timeoutMs: number) {
|
|
return async function timeoutMiddleware(ctx: AppContext, next: Next) {
|
|
// Store the original timeout so we can restore it later
|
|
const originalTimeout = ctx.req.socket.timeout || 0;
|
|
|
|
// Set the new timeout on the socket
|
|
ctx.req.socket.setTimeout(timeoutMs);
|
|
|
|
try {
|
|
await next();
|
|
} finally {
|
|
// Restore the original timeout after the request completes
|
|
ctx.req.socket.setTimeout(originalTimeout);
|
|
}
|
|
};
|
|
}
|