1.0.46 • Published 9 years ago
koa-grace-proxy v1.0.46
koa-grace-proxy
KOA-grace绑定数据的中间件
Install
$ npm install koa-grace-proxy --save
Usage
proxy(app, options)
- app: {Object} koa instance.
- options: {Object|String->root}
- api: {String} api配置项,例如local对应http://localhost:3000,则为:api:{local:'http://localhost:3000'}
app.js
'use strict';
var koa = require('koa');
var proxy = require('..');
var app = koa();
// 配置api
app.use(proxy(app, {
api: {
github: 'https://avatars.githubusercontent.com/'
},{
timeout: 15000 // 超时时间
}
}));
app.use(function*() {
let data;
// 数据请求
if (this.path == '/data/1') {
this.body = {
user_id: '111111'
}
return;
} else if (this.path == '/data/2') {
this.body = {
user_id: '222222'
}
return;
}
// 代理数据
yield this.proxy({
data1: 'http://127.0.0.1:3000/data/1',
data2: 'http://127.0.0.1:3000/data/2',
data3: 'http://test'
});
this.body = this.backData || 'test';
// 代理请求
// yield this.download('github:u/1962352?v=3');
// yield this.download('http://127.0.0.1:9080/bg_3_s.jpg');
// data = yield this.download('http://test.mlsfe.biz/home');
console.log('request done');
});
app.listen(3000, function() {
console.log('Listening on 3000!');
});
Test
npm test
License
MIT
1.0.46
9 years ago
1.0.45
9 years ago
1.0.44
9 years ago
1.0.43
9 years ago
1.0.42
9 years ago
1.0.41
9 years ago
1.0.40
9 years ago
1.0.39
9 years ago
1.0.37
9 years ago
1.0.36
9 years ago
1.0.35
9 years ago
1.0.34
9 years ago
1.0.33
9 years ago
1.0.32
9 years ago
1.0.31
9 years ago
1.0.30
9 years ago
1.0.29
9 years ago
1.0.28
9 years ago
1.0.27
9 years ago
1.0.26
9 years ago
1.0.25
9 years ago
1.0.24
9 years ago
1.0.23
9 years ago
1.0.22
9 years ago
1.0.21
9 years ago
1.0.20
9 years ago
1.0.19
9 years ago
1.0.18
9 years ago
1.0.17
9 years ago
1.0.16
9 years ago
1.0.15
9 years ago
1.0.14
9 years ago
1.0.13
9 years ago
1.0.12
9 years ago
1.0.11
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago