egg-thrift-mock
thrift请求的mock服务,支持多种使用方式。
基本配置Config
configthriftMock = TGatewayCityMappingService: idl: path service: port: 9903 mockFile: '/app/service/city-id-transition/CityIdTransition.json' ;
使用方式
方式一:开发时在本地启动mock服务器
// start.jsconst createServer = ; /* 配置示例 { TSayHelloService: { idl: 'test/thrift/hello/hello.thrift', service: require('./thrift/hello/gen-nodejs/TSayHelloService'), port: 9903 }, }*/let cfgs = ; if typeof cfgs === 'string' cfgs = JSON; ;
方式二:作为egg插件使用全局对象
// app/controller/thrift.jsmodule Controller async { const result = await appthriftMocker; const ctx = this; ctxstatus = 200; ctxbody = success: true data: resultdata ; };
方式三:作为egg插件做中间件使用
拦截请求,直接请求以下格式url即可。 url举例:
const mockUrl = `http:///thrift-mock//`
方式四:自定义数据mock方法
支持mock规则自定义。
使用方法详见example/custom-mock-example.js
。
其他
欢迎各类纠错和补充。谢谢大家~