koa-pixie-proxy

1.0.7 • Public • Published

pixie-proxy

A dirt-simple composable koajs proxy.

Installation

npm i --save koa-pixie-proxy

Usage

var pixie = require('koa-pixie-proxy');
var koa = require('koa');
var router = require('koa-router');
 
var app = koa();
app.use(router(app));
 
var proxy = pixie({host: 'http://example.com'});
 
// Proxy requests to server/hurp to example.com/durp
app.get('/hurp', proxy('/durp'));
 
// works with url params as long as they match the url params
// in the request to your server
app.get('some/:param/here/:id', proxy('someother/:param/maybesomethingelse/:id/durp'));
 
// if you leave out a url it proxies to host + this.url
app.post('/foobar', proxy());

To allow later middleware to modify the response, koa-pixie-proxy will set response headers, status and body but won't actually send the result to the client. This means you give up nice proxy pipelining, but you can do things like modify the result of a proxy like this:

app.get('/hurp', proxy('/durp'), function*() {
  // add a property to the body already proxied
  this.body.beans = 'baz'
});

Readme

Keywords

Package Sidebar

Install

npm i koa-pixie-proxy

Weekly Downloads

1

Version

1.0.7

License

MIT

Last publish

Collaborators

  • jergason