API โบ @builder.io/qwik-city/middleware/request-handler
AbortMessage
export declare class AbortMessage
append
Appends a Response
cookie header using the Set-Cookie
header.
The difference between set()
and append()
is that if the specified header already exists, set()
will overwrite the existing value with the new one, whereas append()
will append the new value onto the end of the set of values.
append(name: string, value: string | number | Record<string, any>, options?: CookieOptions): void;
Parameter | Type | Description |
---|---|---|
name | string | |
value | string | number | Record<string, any> | |
options | (Optional) |
Returns:
void
CacheControl
export type CacheControl =
| CacheControlOptions
| number
| "day"
| "week"
| "month"
| "year"
| "no-cache"
| "immutable"
| "private";
ClientConn
export interface ClientConn
Property | Modifiers | Type | Description |
---|---|---|---|
string | (Optional) | ||
string | (Optional) |
Cookie
export interface Cookie
Method | Description |
---|---|
Appends a The difference between | |
Deletes cookie value by name using the | |
Gets a | |
Gets all | |
Checks if the | |
Returns an array of all the set | |
Sets a |
CookieOptions
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
export interface CookieOptions
Property | Modifiers | Type | Description |
---|---|---|---|
string | (Optional) Defines the host to which the cookie will be sent. If omitted, this attribute defaults to the host of the current document URL, not including subdomains. | ||
Date | string | (Optional) Indicates the maximum lifetime of the cookie as an HTTP-date timestamp. If both | ||
boolean | (Optional) Forbids JavaScript from accessing the cookie, for example, through the | ||
number | [number, 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks'] | (Optional) Indicates the number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. If both | ||
string | (Optional) Indicates the path that must exist in the requested URL for the browser to send the Cookie header. | ||
'strict' | 'lax' | 'none' | 'Strict' | 'Lax' | 'None' | boolean | (Optional) Controls whether or not a cookie is sent with cross-site requests, providing some protection against cross-site request forgery attacks (CSRF). | ||
boolean | (Optional) Indicates that the cookie is sent to the server only when a request is made with the |
CookieValue
export interface CookieValue
Property | Modifiers | Type | Description |
---|---|---|---|
<T = unknown>() => T | |||
() => number | |||
string |
data
data: T;
DeferReturn
export type DeferReturn<T> = () => Promise<T>;
delete
Deletes cookie value by name using the Response
cookie header.
delete(name: string, options?: Pick<CookieOptions, 'path' | 'domain' | 'sameSite'>): void;
Parameter | Type | Description |
---|---|---|
name | string | |
options | Pick<CookieOptions, 'path' | 'domain' | 'sameSite'> | (Optional) |
Returns:
void
EnvGetter
export interface EnvGetter
Method | Description |
---|---|
get
Gets a Request
cookie header value by name.
get(name: string): CookieValue | null;
Parameter | Type | Description |
---|---|---|
name | string |
Returns:
CookieValue | null
getAll
Gets all Request
cookie headers.
getAll(): Record<string, CookieValue>;
Returns:
Record<string, CookieValue>
getErrorHtml
export declare function getErrorHtml(status: number, e: any): string;
Parameter | Type | Description |
---|---|---|
status | number | |
e | any |
Returns:
string
has
Checks if the Request
cookie header name exists.
has(name: string): boolean;
Parameter | Type | Description |
---|---|---|
name | string |
Returns:
boolean
headers
Returns an array of all the set Response
Set-Cookie
header values.
headers(): string[];
Returns:
string[]
mergeHeadersCookies
mergeHeadersCookies: (headers: Headers, cookies: CookieInterface) => Headers;
Parameter | Type | Description |
---|---|---|
headers | Headers | |
cookies |
Returns:
Headers
RedirectMessage
export declare class RedirectMessage extends AbortMessage
Extends: AbortMessage
RequestEvent
export interface RequestEvent<PLATFORM = QwikCityPlatform> extends RequestEventCommon<PLATFORM>
Extends: RequestEventCommon<PLATFORM>
Property | Modifiers | Type | Description |
---|---|---|---|
| boolean | True if the middleware chain has finished executing. | |
| () => WritableStream<Uint8Array> | Low-level access to write to the HTTP response stream. Once | |
| boolean | True if headers have been sent, preventing any more headers from being set. | |
| () => Promise<void> | Invoke the next middleware function in the chain. NOTE: Ensure that the call to |
RequestEventAction
export interface RequestEventAction<PLATFORM = QwikCityPlatform> extends RequestEventCommon<PLATFORM>
Extends: RequestEventCommon<PLATFORM>
Property | Modifiers | Type | Description |
---|---|---|---|
<T extends Record<string, any>>(status: number, returnData: T) => FailReturn<T> |
RequestEventBase
export interface RequestEventBase<PLATFORM = QwikCityPlatform>
Property | Modifiers | Type | Description |
---|---|---|---|
| string | The base pathname of the request, which can be configured at build time. Defaults to | |
| (cacheControl: CacheControl, target?: CacheControlTarget) => void | Convenience method to set the Cache-Control header. Depending on your CDN, you may want to add another cacheControl with the second argument set to See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control and https://qwik.dev/docs/caching/\#CDN-Cache-Controls for more information. | |
| Provides information about the client connection, such as the IP address and the country the request originated from. | ||
| HTTP request and response cookie. Use the | ||
| Platform provided environment variables. | ||
| Headers | HTTP response headers. Notice it will be empty until you first add a header. If you want to read the request headers, use https://developer.mozilla.org/en-US/docs/Glossary/Response\_header | |
| string | HTTP request method. | |
| Readonly<Record<string, string>> | URL path params which have been parsed from the current url pathname segments. Use | |
| () => Promise<unknown> | This method will check the request headers for a If the | |
| string | URL pathname. Does not include the protocol, domain, query string (search params) or hash. https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname | |
| PLATFORM | Platform specific data and functions | |
| URLSearchParams | URL Query Strings (URL Search Params). Use https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams | |
| Request | HTTP request information. | |
| Map<string, any> | Shared Map across all the request handlers. Every HTTP request will get a new instance of the shared map. The shared map is useful for sharing data between request handlers. | |
| AbortSignal | Request's AbortSignal (same as | |
| URL | HTTP request URL. |
RequestEventCommon
export interface RequestEventCommon<PLATFORM = QwikCityPlatform> extends RequestEventBase<PLATFORM>
Extends: RequestEventBase<PLATFORM>
Property | Modifiers | Type | Description |
---|---|---|---|
| <T = any>(statusCode: ErrorCodes, message: T) => ServerError<T> | When called, the response will immediately end with the given status code. This could be useful to end a response with | |
| () => AbortMessage | ||
| (statusCode: StatusCodes, html: string) => AbortMessage | Convenience method to send an HTML body response. The response will be automatically set the | |
| (statusCode: StatusCodes, data: any) => AbortMessage | Convenience method to JSON stringify the data and send it in the response. The response will be automatically set the | |
| (local?: string) => string | Which locale the content is in. The locale value can be retrieved from selected methods using | |
| (statusCode: RedirectCode, url: string) => RedirectMessage | URL to redirect to. When called, the response will immediately end with the correct redirect status and headers. https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections | |
| SendMethod | Send a body response. The | |
| (statusCode?: StatusCodes) => number | HTTP response status code. Sets the status code when called with an argument. Always returns the status code, so calling | |
| (statusCode: StatusCodes, text: string) => AbortMessage | Convenience method to send an text body response. The response will be automatically set the |
RequestEventLoader
export interface RequestEventLoader<PLATFORM = QwikCityPlatform> extends RequestEventAction<PLATFORM>
Extends: RequestEventAction<PLATFORM>
Property | Modifiers | Type | Description |
---|---|---|---|
<T>(returnData: Promise<T> | (() => Promise<T>)) => DeferReturn<T> | |||
requestHandler
export type RequestHandler<PLATFORM = QwikCityPlatform> = (
ev: RequestEvent<PLATFORM>,
) => Promise<void> | void;
References: RequestEvent
RequestHandler
export type RequestHandler<PLATFORM = QwikCityPlatform> = (
ev: RequestEvent<PLATFORM>,
) => Promise<void> | void;
References: RequestEvent
ResolveSyncValue
export interface ResolveSyncValue
ResolveValue
export interface ResolveValue
ServerError
export declare class ServerError<T = any> extends Error
Extends: Error
Constructor | Modifiers | Description |
---|---|---|
Constructs a new instance of the |
Property | Modifiers | Type | Description |
---|---|---|---|
T | |||
number |
ServerRenderOptions
export interface ServerRenderOptions extends RenderOptions
Extends: RenderOptions
Property | Modifiers | Type | Description |
---|---|---|---|
boolean | (Optional) Protection against cross-site request forgery (CSRF) attacks. When Be careful when disabling this option as it may lead to CSRF attacks. Defaults to | ||
QwikCityPlan | |||
Render |
ServerRequestEvent
Request event created by the server.
export interface ServerRequestEvent<T = unknown>
Property | Modifiers | Type | Description |
---|---|---|---|
() => ClientConn | |||
string | undefined | |||
QwikCityPlatform | |||
Request | |||
URL |
ServerRequestMode
export type ServerRequestMode = "dev" | "static" | "server";
ServerResponseHandler
export type ServerResponseHandler<T = any> = (
status: number,
headers: Headers,
cookies: Cookie,
resolve: (response: T) => void,
requestEv: RequestEventInternal,
) => WritableStream<Uint8Array>;
References: Cookie
set
Sets a Response
cookie header using the Set-Cookie
header.
set(name: string, value: string | number | Record<string, any>, options?: CookieOptions): void;
Parameter | Type | Description |
---|---|---|
name | string | |
value | string | number | Record<string, any> | |
options | (Optional) |
Returns:
void
status
status: number;