/** * Based on definition by DefinitelyTyped: * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts */ import type * as http from 'http'; import type * as httpProxy from 'http-proxy'; import type * as net from 'net'; export type NextFunction void> = T; export interface RequestHandler { (req: TReq, res: TRes, next?: TNext): Promise; upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void; } export type Filter = string | string[] | ((pathname: string, req: TReq) => boolean); export interface Plugin { (proxyServer: httpProxy, options: Options): void; } export interface OnProxyEvent { error?: httpProxy.ErrorCallback; proxyReq?: httpProxy.ProxyReqCallback; proxyReqWs?: httpProxy.ProxyReqWsCallback; proxyRes?: httpProxy.ProxyResCallback; open?: httpProxy.OpenCallback; close?: httpProxy.CloseCallback; start?: httpProxy.StartCallback; end?: httpProxy.EndCallback; econnreset?: httpProxy.EconnresetCallback; } export type Logger = Pick; export interface Options extends httpProxy.ServerOptions { /** * Narrow down requests to proxy or not. * Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server. * Or use the {@link http.IncomingMessage `req`} object for more complex filtering. * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md * @since v3.0.0 */ pathFilter?: Filter; /** * Modify request paths before requests are send to the target. * @example * ```js * createProxyMiddleware({ * pathRewrite: { * '^/api/old-path': '/api/new-path', // rewrite path * } * }); * ``` * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md */ pathRewrite?: { [regexp: string]: string; } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise); /** * Access the internal http-proxy server instance to customize behavior * * @example * ```js * createProxyMiddleware({ * plugins: [(proxyServer, options) => { * proxyServer.on('error', (error, req, res) => { * console.error(error); * }); * }] * }); * ``` * @link https://github.com/chimurai/http-proxy-middleware#plugins-array * @since v3.0.0 */ plugins?: Plugin[]; /** * Eject pre-configured plugins. * NOTE: register your own error handlers to prevent server from crashing. * * @link https://github.com/chimurai/http-proxy-middleware#ejectplugins-boolean-default-false * @since v3.0.0 */ ejectPlugins?: boolean; /** * Listen to http-proxy events * @see {@link OnProxyEvent} for available events * @example * ```js * createProxyMiddleware({ * on: { * error: (error, req, res, target) => { * console.error(error); * } * } * }); * ``` * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/proxy-events.md * @since v3.0.0 */ on?: OnProxyEvent; /** * Dynamically set the {@link Options.target `options.target`}. * @example * ```js * createProxyMiddleware({ * router: async (req) => { * return 'http://127:0.0.1:3000'; * } * }); * ``` * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md */ router?: { [hostOrPath: string]: httpProxy.ServerOptions['target']; } | ((req: TReq) => httpProxy.ServerOptions['target']) | ((req: TReq) => Promise); /** * Log information from http-proxy-middleware * @example * ```js * createProxyMiddleware({ * logger: console * }); * ``` * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md * @since v3.0.0 */ logger?: Logger | any; }