0.8.0 • Published 8 years ago

koa-forward-request v0.8.0

Weekly downloads
231
License
MIT
Repository
github
Last release
8 years ago

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

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

9 years ago

0.6.0

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago