• Version 2.0.1
  • Published
  • 63.6 kB
  • 5 dependencies
  • MIT license


npm i http-proxy-middleware
yarn add http-proxy-middleware
pnpm add http-proxy-middleware


The one-liner node.js proxy middleware for connect, express and browser-sync



function createProxyMiddleware

createProxyMiddleware: (
context: Filter | Options,
options?: Options
) => import('./types').RequestHandler;

    function fixRequestBody

    fixRequestBody: (proxyReq: any, req: any) => void;
    • Fix proxied body if bodyParser is involved.

    function responseInterceptor

    responseInterceptor: (
    interceptor: Interceptor
    ) => (proxyRes: any, req: any, res: any) => Promise<void>;
    • Intercept responses from upstream. Automatically decompress (deflate, gzip, brotli). Give developer the opportunity to modify intercepted Buffer and http.ServerResponse

      NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())


    interface Options

    interface Options extends httpProxy.ServerOptions {}

      property logLevel

      logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';

        property logProvider

        logProvider?: LogProviderCallback;

          property onClose

          onClose?: OnCloseCallback;

            property onError

            onError?: OnErrorCallback;

              property onOpen

              onOpen?: OnOpenCallback;

                property onProxyReq

                onProxyReq?: OnProxyReqCallback;

                  property onProxyReqWs

                  onProxyReqWs?: OnProxyReqWsCallback;

                    property onProxyRes

                    onProxyRes?: OnProxyResCallback;

                      property pathRewrite

                      | {
                      [regexp: string]: string;
                      | ((path: string, req: Request) => string)
                      | ((path: string, req: Request) => Promise<string>);

                        property router

                        | {
                        [hostOrPath: string]: httpProxy.ServerOptions['target'];
                        | ((req: Request) => httpProxy.ServerOptions['target'])
                        | ((req: Request) => Promise<httpProxy.ServerOptions['target']>);

                          interface RequestHandler

                          interface RequestHandler extends express.RequestHandler {}

                            property upgrade

                            upgrade?: (req: Request, socket: net.Socket, head: any) => void;

                              Type Aliases

                              type Filter

                              type Filter = string | string[] | ((pathname: string, req: Request) => boolean);

                                Package Files (4)

                                Dependencies (5)

                                Dev Dependencies (29)

                                Peer Dependencies (0)

                                No peer dependencies.


                                To add a badge like this badgeto your package's README, use the codes available below.

                                You may also use to create a custom badge linking to

                                • Markdown
                                • HTML
                                  <a href=""><img src="" alt=""></a>