egg-apiproxy
egg Request lib
Installation
npm i -S egg-apiproxy
Usages
- 开启插件
// config/plugin.jsexportsapiproxy = enable: true package: 'egg-apiproxy';
- 使用方式
// config/config.default.jsapiproxy: defaults: key: 'key-和后端约定' client: // dataKey: 'data', caller: 'caller-和后端约定' options: timeout: 10000 passHeaderKeys: 'Cookie' 'token' // config/config.${env}.jsapiproxy: server: test: host: 'http://10.1.1.36:8888' // app/service/Test.jsmodule { CommonProxy { superctx; thishostname = 'test'; // 对应 config/config.${env}.js 中 apiproxy.server.test的配置 } // _transformResponse(result, config, response) { // result = super._transformResponse(result, config, response); // return newResult; // } async { const opts = method: 'GET' // 默认 POST service: '/sys/user/info' data page // client: {}, // headers: {}, ; return await this; } return TestProxy;}; // app/controller/test.jsconst result = await servicetest;
Issues
Submit the issues if you find any bug or have any suggestion.
Contribution
Fork the repository and submit pull requests.