# koa-proxy

> Proxy middleware for koa

Latest version **1.0.0-alpha.3** (published 2019-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-proxy
pnpm add koa-proxy
yarn add koa-proxy
bun add koa-proxy
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.3 |
| Published | 2019-07-23 |
| First published | 2014-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-proxy) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 45 |
| Author | edorivai |
| Maintainers | edorivai |
| Keywords | koa, middleware, proxy |

## Links

- npm: https://www.npmjs.com/package/koa-proxy
- Repository: https://github.com/edorivai/koa-proxy
- Issues: https://github.com/edorivai/koa-proxy/issues
- npm.io page: https://npm.io/package/koa-proxy

## Dependencies (3)

- [request](https://npm.io/package/request.md) ^2.88.0
- [pause-stream](https://npm.io/package/pause-stream.md) 0.0.11
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.5

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0-alpha.3 (latest) — 2019-07-23
- 1.0.0-alpha.2 — 2019-06-06
- 1.0.0-alpha.1 — 2019-06-06
- 1.0.0-alpha.0 — 2019-04-29
- 0.9.0 — 2017-09-04
- 0.8.0 — 2017-02-02
- 0.7.0 — 2016-12-27
- 0.6.0 — 2016-04-27
- 0.5.0 — 2016-02-24
- 0.4.1 — 2015-10-09
- 0.4.0 — 2015-09-09
- 0.3.0 — 2015-07-03
- 0.2.0 — 2014-10-28
- 0.1.3 — 2014-08-20
- 0.1.2 — 2014-08-01
- … 2 more at https://npm.io/package/koa-proxy/versions

## README

# koa-proxy [![Build Status](https://travis-ci.com/edorivai/koa-proxy.svg?branch=master)](https://travis-ci.com/edorivai/koa-proxy)

Proxy middleware for koa

---

## Install

```
$ npm install koa-proxy -S
```

## Usage

When you request http://localhost:3000/index.js, it will fetch http://alicdn.com/index.js and return.

```js
var koa = require('koa');
var proxy = require('koa-proxy');
var app = koa();
app.use(proxy({
  host: 'http://alicdn.com'
}));
app.listen(3000);
```

You can proxy a specified url.

```js
app.get('index.js', proxy({
  url: 'http://alicdn.com/index.js'
}));
```

You can specify a key/value object that can map your request's path to the other.

```js
app.get('index.js', proxy({
  host: 'http://alicdn.com',
  map: {
    'index.js': 'index-1.js'
  }
}));
```

You can specify a function that can map your request's path to the desired destination.

```js
app.get('index.js', proxy({
  host: 'http://alicdn.com',
  map: function(path) { return 'public/' + path; }
}));
```

You can specify match criteria to restrict proxy calls to a given path.

```js
app.use(proxy({
  host:  'http://alicdn.com', // proxy alicdn.com...
  match: /^\/static\//        // ...just the /static folder
}));
```

Or you can use match to exclude a specific path.

```js
app.use(proxy({
  host:  'http://alicdn.com',     // proxy alicdn.com...
  match: /^(?!\/dontproxy\.html)/ // ...everything except /dontproxy.html
}));
```

Proxy won't send cookie to real server, you can set `jar = true` to send it.

```js
app.use(proxy({
  jar: true,
}));
```

Proxy won't send 'foo' and 'bar' headers to real server, or recieve 'jar-jar' from real server.

```js
app.use(proxy({
  suppressRequestHeaders: ['foo','bar'], // case-insensitive
  suppressResponseHeaders: ['jar-jar'] // case-insensitive
}));
```

You can also add new headers to your response or override existing ones
```js
app.use(proxy({
  overrideResponseHeaders: {
    "cow": "moo",
    "duck": "quack"
    }, 
}));
```

## LICENSE

Copyright (c) 2014 popomore. Licensed under the MIT license.

---
_Source: https://npm.io/package/koa-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
