Forward request for koa, debugging use.
npm i koa-forward-request --save
forward(app[, options])
'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.
see request.
node --harmony example
npm test
MIT