Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | 1x 2x | import { HttpMethod } from "@xtaskjs/common";
export type HttpAdapterType = "fastify";
export interface HttpServerOptions {
port?: number;
host?: string;
}
export interface HttpRequestLike {
method?: string;
url?: string;
path?: string;
body?: any;
}
export interface HttpViewResult {
readonly __xtaskView: true;
template: string;
model?: Record<string, any>;
statusCode?: number;
}
export const view = (
template: string,
model?: Record<string, any>,
statusCode?: number
): HttpViewResult => ({
__xtaskView: true,
template,
model,
statusCode,
});
export interface HttpResponseLike {
statusCode?: number;
headersSent?: boolean;
setHeader?: (name: string, value: string) => void;
end?: (chunk?: any) => void;
json?: (payload: any) => void;
send?: (payload: any) => void;
status?: (code: number) => HttpResponseLike;
code?: (code: number) => HttpResponseLike;
header?: (name: string, value: string) => HttpResponseLike;
view?: (template: string, locals?: Record<string, any>) => any;
}
export type HttpRequestHandler = (
method: HttpMethod,
path: string,
req: HttpRequestLike,
res: HttpResponseLike
) => Promise<void>;
export interface HttpAdapter {
readonly type: HttpAdapterType;
registerRequestHandler(handler: HttpRequestHandler): void;
renderView?(req: HttpRequestLike, res: HttpResponseLike, payload: HttpViewResult): Promise<void>;
listen(options: Required<HttpServerOptions>): Promise<void>;
close(): Promise<void>;
}
export interface FastifyTemplateEngineOptions {
viewsPath?: string;
fileExtension?: string;
render?: (
template: string,
model: Record<string, any>,
context: { req: HttpRequestLike; res: HttpResponseLike }
) => string | Promise<string>;
nativeRender?: (res: HttpResponseLike, template: string, model: Record<string, any>) => Promise<any>;
}
export interface FastifyStaticFilesOptions {
enabled?: boolean;
publicPath?: string;
urlPrefix?: string;
}
export interface FastifyAdapterOptions {
templateEngine?: FastifyTemplateEngineOptions;
staticFiles?: FastifyStaticFilesOptions;
}
|