@ctsy/koa-better-proxy
A Better Koa Proxy middleware, support more proxy rule
Last updated 2 months ago by yanpengquan .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @ctsy/koa-better-proxy 
SYNC missed versions from official npm registry.

koa-better-proxy

A Better Koa Proxy middleware, support more proxy rule (base on koa-proxy <github.com/popomore/koa-proxy>)


Install

$ npm install koa-better-proxy -S

Usage

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

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

You can proxy a specified url.

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.

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.

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.

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.

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.

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

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

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

LICENSE

Copyright (c) 2018 qieguo. Licensed under the MIT license.

Current Tags

  • 0.1.1                                ...           latest (2 months ago)

2 Versions

  • 0.1.1                                ...           2 months ago
  • 0.1.0                                ...           2 months ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |