UNPKG

@whatwg-node/server

Version:

Fetch API compliant HTTP Server adapter

39 lines (38 loc) 1.4 kB
import { ServerAdapterPlugin } from '../plugins/types.js'; import type { FetchAPI } from '../types.js'; interface UWSServerContext { req: UWSRequest; res: UWSResponse; } export declare function useUWSAdapter(): ServerAdapterPlugin<UWSServerContext>; export interface UWSRequest { getMethod(): string; forEach(callback: (key: string, value: string) => void): void; getUrl(): string; getHeader(key: string): string | undefined; setYield(y: boolean): void; } export interface UWSResponse { onData(callback: (chunk: ArrayBuffer, isLast: boolean) => void): void; onAborted(callback: () => void): void; writeStatus(status: string): void; writeHeader(key: string, value: string): void; end(body?: any): void; close(): void; write(body: any): boolean; cork(callback: () => void): void; } export type UWSHandler = (res: UWSResponse, req: UWSRequest) => void | Promise<void>; export declare function isUWSResponse(res: any): res is UWSResponse; interface GetRequestFromUWSOpts { req: UWSRequest; res: UWSResponse; fetchAPI: FetchAPI; } export declare function getRequestFromUWSRequest({ req, res, fetchAPI }: GetRequestFromUWSOpts): Request; interface SendResponseToUWSOpts { res: UWSResponse; response: Response; } export declare function sendResponseToUwsOpts({ res, response }: SendResponseToUWSOpts): Promise<void>; export {};