http-request-mock
Version:
Intercept & mock http requests issued by XMLHttpRequest, fetch, nodejs https/http module, axios, jquery, superagent, ky, node-fetch, request, got or any other request libraries by intercepting XMLHttpRequest, fetch and nodejs native requests in low level.
67 lines (66 loc) • 2.09 kB
TypeScript
declare const _exports: Server;
export = _exports;
declare class Server {
mockDirectory: any;
listeningAddress: any[];
host: string;
type: string;
minPort: number;
maxPort: number;
/**
* Start a proxy server. Default port: 9091.
*
* @param {string} type
* @param {string} mockDir
* @param {string} environment
* @param {string} proxyMode
*/
init({ type, mockDir, environment, proxyMode }: string): Promise<string>;
/**
* Reload .runtime.js and the specified mock files.
* @param {string[]} files
*/
reload(files?: string[]): void;
/**
* Server listener.
* @param {object} req
* @param {object} res
*/
requestListener(req: object, res: object): Promise<any>;
doMockResponse(req: any, res: any, request: any, mockItem: any): Promise<any>;
doRemoteMockResponse(res: any, request: any, mockItem: any, remoteResponse: any): Promise<string>;
/**
* Check http-request-mock inner message from browser.
* @param {object} mocker
* @param {object} req
* @param {object} res
*/
checkHttpRequestMockInnerMsg(mocker: object, req: object, res: object): boolean;
/**
* Display all mock list for server index.
* @param {object} mocker
* @param {object} req
* @param {object} res
*/
checkServerIndex(req: object, res: object): boolean;
/**
* Parse received raw request information and return the proxied information.
* @param {object} request
*/
parseRequest(request: object): Promise<unknown>;
/**
* Proxy the received request to the specified url.
* The specified url is with protocol such as: http://jsonplaceholder.typicode.com/todos/1
* @param {object} req
* @param {object} res
* @param {string} url
* @returns
*/
doProxy(req: object, res: object, url: string, handler: any): Promise<any>;
/**
* Send an internal server error.
* @param {object} res
* @param {string} body
*/
serverError(res: object, body?: string): void;
}