UNPKG

cassava

Version:
45 lines (44 loc) 1.54 kB
/// <reference types="node" /> import * as http from "http"; import { Route } from "./Route"; import { RouterEvent } from "../RouterEvent"; import { RouterResponse } from "../RouterResponse"; /** * Proxies requests to another server. */ export declare class ProxyRoute implements Route { readonly config: ProxyRouteConfig; private parsedDest; constructor(config: ProxyRouteConfig); matches(evt: RouterEvent): boolean; handle(evt: RouterEvent): Promise<RouterResponse | null>; private getRequestBodyContentType; } export interface ProxyRouteConfig { /** * The root of the REST path to start proxying. */ srcPath: string; /** * The destination to proxy to. */ destPath: string; /** * Optional additional headers to send with the request. */ additionalHeaders?: { [key: string]: string; }; /** * Optional mapper function to alter the ClientRequestArgs before sending it. Can return * the altered ClientRequestArgs or a Promise resolving to a ClientRequestArgs to * continue with the request. Can return `null` or a Promise resolving to `null` to * cancel the request. */ requestMapper?: (reqArgs: http.ClientRequestArgs) => Promise<http.ClientRequestArgs | null> | http.ClientRequestArgs | null; /** * Optional mapper function to alter the request body (if any) before sending the request. * Can return `undefined` to not send a body. */ bodyMapper?: (reqBody: any) => Promise<any> | any; }