UNPKG

@tdb/web

Version:

Common condiguration for serving a web-site and testing web-based UI components.

47 lines (46 loc) 1.45 kB
/// <reference types="node" /> import { Url } from 'url'; import { Request, Response, RequestHandler, NextFunction } from 'express'; export { Request, Response, RequestHandler, NextFunction }; export declare type IUrlQuery = { [key: string]: string; }; export declare type IDocumentGetInitialProps = { pathname: string; query: IUrlQuery; asPath: string; req: Request; res: Response; err: RequestError; renderPage: () => any; }; export declare type RequestError = { statusCode: number; }; export declare type IRegisterHttpHandler = (url: string, handler: RequestHandler) => IWebApp; export declare type RedirectPath = (args: { url: Url; params: { [key: string]: string | number | boolean; }; }) => string; export declare type IWebApp = { isStarted: boolean; use: (...handlers: Array<RequestHandler | IWebApp>) => IWebApp; redirect: (fromPath: string, toPath: RedirectPath | string) => IWebApp; file: (urlPath: string, filePath: string) => IWebApp; static: (urlPath: string, dirPath: string) => IWebApp; render: (urlPath: string, pagePath?: string) => IWebApp; get: IRegisterHttpHandler; post: IRegisterHttpHandler; put: IRegisterHttpHandler; delete: IRegisterHttpHandler; start: (port?: number) => Promise<IWebApp>; }; export interface IWebAppOptions { dir?: string; static?: string; dev?: boolean; port?: number; silent?: boolean; }