开源软件名称:nswbmw/koa-forward-request
开源软件地址:https://github.com/nswbmw/koa-forward-request
开源编程语言:
JavaScript
100.0%
开源软件介绍:koa-forward-request
Forward request for koa, debugging use.
Install
npm i koa-forward-request --save
Usage
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
Test
License
MIT
|
请发表评论