Skip to content

Interface: ElysiaNestMiddleware

Defined in: packages/core/src/interfaces/middleware.interface.ts:12

Interface for class-based middleware. Instances will be resolved from the DI container.

Methods

use()

ts
use(context, next): any;

Defined in: packages/core/src/interfaces/middleware.interface.ts:13

Parameters

ParameterTypeDescription
context{ body: unknown; cookie: Record<string, Cookie<unknown>>; headers: Record<string, string | undefined>; params: Record<string, string>; path: string; query: Record<string, string>; redirect: (url, status?) => Response; request: Request; route: string; server: Server<unknown> | null; set: { cookie?: Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>; headers: HTTPHeaders; redirect?: string; status?: | number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"; }; status: <Code, T>(code, response?) => ElysiaCustomStatusResponse<Code, T, Code extends | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? { Accepted: 202; Already Reported: 208; Bad Gateway: 502; Bad Request: 400; Conflict: 409; Continue: 100; Created: 201; Early Hints: 103; Enhance Your Calm: 420; Expectation Failed: 417; Failed Dependency: 424; Forbidden: 403; Found: 302; Gateway Timeout: 504; Gone: 410; HTTP Version Not Supported: 505; I'm a teapot: 418; Insufficient Storage: 507; Internal Server Error: 500; Length Required: 411; Locked: 423; Loop Detected: 508; Method Not Allowed: 405; Misdirected Request: 421; Moved Permanently: 301; Multi-Status: 207; Multiple Choices: 300; Network Authentication Required: 511; No Content: 204; Non-Authoritative Information: 203; Not Acceptable: 406; Not Extended: 510; Not Found: 404; Not Implemented: 501; Not Modified: 304; OK: 200; Partial Content: 206; Payload Too Large: 413; Payment Required: 402; Permanent Redirect: 308; Precondition Failed: 412; Precondition Required: 428; Processing: 102; Proxy Authentication Required: 407; Range Not Satisfiable: 416; Request Header Fields Too Large: 431; Request Timeout: 408; Reset Content: 205; See Other: 303; Service Unavailable: 503; Switching Protocols: 101; Temporary Redirect: 307; Too Early: 425; Too Many Requests: 429; Unauthorized: 401; Unavailable For Legal Reasons: 451; Unprocessable Content: 422; Unsupported Media Type: 415; Upgrade Required: 426; URI Too Long: 414; Variant Also Negotiates: 506; }[Code] : Code>; store: { }; }-
context.bodyunknown-
context.cookieRecord<string, Cookie<unknown>>-
context.headersRecord<string, string | undefined>-
context.paramsRecord<string, string>-
context.pathstringPath extracted from incoming URL Represent a value extracted from URL Example '/id/9'
context.queryRecord<string, string>-
context.redirect(url, status?) => Response-
context.requestRequest-
context.routestringPath as registered to router Represent a path registered to a router, not a URL Example '/id/:id'
context.serverServer<unknown> | null-
context.set{ cookie?: Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>; headers: HTTPHeaders; redirect?: string; status?: | number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"; }-
context.set.cookie?Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>! Internal Property Use Context.cookie instead
context.set.headersHTTPHeaders-
context.set.redirect?stringDeprecated Use inline redirect instead Example Migration example new Elysia() .get(({ redirect }) => redirect('/'))
context.set.status?| number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"-
context.status<Code, T>(code, response?) => ElysiaCustomStatusResponse<Code, T, Code extends | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? { Accepted: 202; Already Reported: 208; Bad Gateway: 502; Bad Request: 400; Conflict: 409; Continue: 100; Created: 201; Early Hints: 103; Enhance Your Calm: 420; Expectation Failed: 417; Failed Dependency: 424; Forbidden: 403; Found: 302; Gateway Timeout: 504; Gone: 410; HTTP Version Not Supported: 505; I'm a teapot: 418; Insufficient Storage: 507; Internal Server Error: 500; Length Required: 411; Locked: 423; Loop Detected: 508; Method Not Allowed: 405; Misdirected Request: 421; Moved Permanently: 301; Multi-Status: 207; Multiple Choices: 300; Network Authentication Required: 511; No Content: 204; Non-Authoritative Information: 203; Not Acceptable: 406; Not Extended: 510; Not Found: 404; Not Implemented: 501; Not Modified: 304; OK: 200; Partial Content: 206; Payload Too Large: 413; Payment Required: 402; Permanent Redirect: 308; Precondition Failed: 412; Precondition Required: 428; Processing: 102; Proxy Authentication Required: 407; Range Not Satisfiable: 416; Request Header Fields Too Large: 431; Request Timeout: 408; Reset Content: 205; See Other: 303; Service Unavailable: 503; Switching Protocols: 101; Temporary Redirect: 307; Too Early: 425; Too Many Requests: 429; Unauthorized: 401; Unavailable For Legal Reasons: 451; Unprocessable Content: 422; Unsupported Media Type: 415; Upgrade Required: 426; URI Too Long: 414; Variant Also Negotiates: 506; }[Code] : Code>-
context.store{ }-
next() => Promise<any>-

Returns

any

Released under the MIT License.