koa-forward-request

0.8.0 • Public • Published

koa-forward-request

Forward request for koa, debugging use.

Install

npm i koa-forward-request --save

Usage

forward(app[, options])

Example

'use strict';

var app = require('koa')();
var route = require('koa-route');
var logger = require('koa-logger');

var forward = require('./');

forward(app, {
  debug: true
});

app.use(logger());

app.use(route.get('/', function* () {
  this.forward('/test');
}));

app.use(route.get('/test', function* () {
  this.body = 'test';
}));

app.listen(3000);

or

'use strict';

var app = require('koa')();
var route = require('koa-route');
var koaBody = require('koa-body');
var logger = require('koa-logger');

var forward = require('./');

forward(app, {
  debug: true
});

app.use(logger());
app.use(koaBody());

app.use(route.post('/', function* () {
  this.forward('/test');
}));

app.use(route.post('/test', function* () {
  this.body = 'test';
}));

app.listen(3000);

or

'use strict';

var app = require('koa')();
var route = require('koa-route');
var koaBody = require('koa-body');

var forward = require('./');

forward(app, {
  baseUrl: 'http://api.example.com'
});

app.use(koaBody());
app.use(forward.all());// forward all request to 'http://api.example.com'

app.listen(3000);

NB: If you set content-type to multipart/form-data for uploading file, please use koa-body and enable multipart option.

Options

see request.

Example

node --harmony example

Test

npm test

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i koa-forward-request

Weekly Downloads

20

Version

0.8.0

License

MIT

Last publish

Collaborators

  • nswbmw