1.1.2 • Published 3 years ago

@erwinv/koa-http-proxy v1.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

koa-http-proxy

Koa HTTP proxy middleware powered by http-party/node-http-proxy.

Installation

npm install --save @erwinv/koa-http-proxy

Usage

import { KoaHttpProxy } from '@erwinv/koa-http-proxy'

import { default as Koa, Middleware } from 'koa'

new Koa()
  .use(KoaHttpProxy(process.env.PROXY_TARGET, {
    xfwd: true,
    changeOrigin: true,
    followRedirects: true,
    proxyTimeout: 60 * 1000,
  }))
  .listen(process.env.PORT)

Options

Inherited from third-party dependency

These options are the same as those of http-party/node-http-proxy with the following exceptions:

  • target: same type but is moved outside of the options object and should be passed as first argument to the middleware factory function instead
  • ws: WebSockets not supported
  • selfHandleResponse: not supported (middleware internals depends on this being always false)

Own

  • bufferResponseBody: boolean, default: false - if true, the proxied response will be buffered in full before sending it to client (useful for proxies that need to modify/decorate the JSON response body for example). Otherwise (if false), the proxied response is streamed directly to the client. Note: the buffered response body is a Buffer and may need to be decompressed (depending on Content-Encoding), stringified, and/or parsed (depending on Content-Type) before it can be read or modified.