1.0.46 • Published 7 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
7 years ago
1.0.45
7 years ago
1.0.44
7 years ago
1.0.43
7 years ago
1.0.42
7 years ago
1.0.41
8 years ago
1.0.40
8 years ago
1.0.39
8 years ago
1.0.37
8 years ago
1.0.36
8 years ago
1.0.35
8 years ago
1.0.34
8 years ago
1.0.33
8 years ago
1.0.32
8 years ago
1.0.31
8 years ago
1.0.30
8 years ago
1.0.29
8 years ago
1.0.28
8 years ago
1.0.27
8 years ago
1.0.26
8 years ago
1.0.25
8 years ago
1.0.24
8 years ago
1.0.23
8 years ago
1.0.22
8 years ago
1.0.21
8 years ago
1.0.20
8 years ago
1.0.19
8 years ago
1.0.18
8 years ago
1.0.17
8 years ago
1.0.16
8 years ago
1.0.15
8 years ago
1.0.14
8 years ago
1.0.13
8 years ago
1.0.12
8 years ago
1.0.11
8 years ago
1.0.9
8 years ago
1.0.8
8 years ago
1.0.7
8 years ago
1.0.6
8 years ago
1.0.5
8 years ago
1.0.4
8 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago