Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nswbmw/koa-forward-request
Forward request for koa.
https://github.com/nswbmw/koa-forward-request
Last synced: 2 months ago
JSON representation
Forward request for koa.
- Host: GitHub
- URL: https://github.com/nswbmw/koa-forward-request
- Owner: nswbmw
- Created: 2015-07-21T09:37:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T11:25:32.000Z (about 8 years ago)
- Last Synced: 2024-11-14T10:54:59.213Z (2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-koa - koa-forward-request - 转发请求。![](https://img.shields.io/github/stars/nswbmw/koa-forward-request.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-forward-request.svg?style=flat-square) (仓库 / 中间件)
README
## 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](https://github.com/request/request#requestoptions-callback).
### Example
node --harmony example
### Test
npm test
### License
MIT