Skip to content

nswbmw/koa-forward-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Forward request for koa.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published