@shuvi/runtime/server
ShuviApiHandler
interface ShuviApiHandler {
(req: ApiRequest, res: ApiResponse): void | Promise<void>;
}
ApiRequest
interface ApiRequest extends IncomingMessage {
url: string;
pathname: string;
query: IQuery;
params: IParams;
cookies: {
[key: string]: string;
};
body?: {
[key: string]: any;
};
}
ApiResponse
interface ApiResponse<T> extends ServerResponse {
send: Send<T>;
json: Send<T>;
status: (statusCode: number) => IApiRes<T>;
redirect(url: string): IApiRes<T>;
redirect(status: number, url: string): IApiRes<T>;
}
HandlePageRequestFunction
type IHandlePageRequest = (req: IncomingMessage, res: ServerResponse) => any;
function handlePageRequest(
originalHandlePageRequest: IHandlePageRequest
): IHandlePageRequest;
ModifyHtmlFunction
type IHtmlAttrs = { textContent?: string } & {
[x: string]: string | number | undefined | boolean;
};
interface IHtmlTag<TagNames = string> {
tagName: TagNames;
attrs: IHtmlAttrs;
innerHTML?: string;
}
interface IHtmlDocument {
htmlAttrs: IHtmlAttrs;
headTags: IHtmlTag<
"meta" | "link" | "style" | "script" | "noscript" | "title"
>[];
mainTags: IHtmlTag[];
scriptTags: IHtmlTag<"script">[];
}
function modifyHtml(
document: IHtmlDocument,
context: {
req: http.IncomingMessage,
appContext: AppContext,
}
): void | Promise<void>;
- type http.IncomingMessage
- type AppContext