{"id":13670890,"url":"https://github.com/kikooo/thrift-mock","last_synced_at":"2025-04-27T13:33:12.565Z","repository":{"id":42222545,"uuid":"131370018","full_name":"kikooo/thrift-mock","owner":"kikooo","description":"An egg.js plugin provides mock function of thrift interface in various ways","archived":false,"fork":false,"pushed_at":"2022-04-09T23:10:36.000Z","size":196,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T03:17:25.320Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kikooo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-28T03:44:20.000Z","updated_at":"2022-05-03T18:32:25.000Z","dependencies_parsed_at":"2022-08-26T05:11:50.215Z","dependency_job_id":null,"html_url":"https://github.com/kikooo/thrift-mock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikooo%2Fthrift-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikooo%2Fthrift-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikooo%2Fthrift-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikooo%2Fthrift-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kikooo","download_url":"https://codeload.github.com/kikooo/thrift-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251145754,"owners_count":21543095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:00:52.189Z","updated_at":"2025-04-27T13:33:07.552Z","avatar_url":"https://github.com/kikooo.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# egg-thrift-mock\n\nthrift请求的mock服务，支持多种使用方式。\n\n## 基本配置Config\n\n```javascript\nconfig.thriftMock = {\n  TGatewayCityMappingService: {\n    idl: path.join(appInfo.baseDir, '/app/service/city-id-transition/CityIdTransition.thrift'),\n    service: require('../app/service/city-id-transition/gen-nodejs/TGatewayCityMappingService'),\n    port: 9903,\n    mockFile: '/app/service/city-id-transition/CityIdTransition.json'\n  }\n};\n```\n\n## 使用方式\n### 方式一：开发时在本地启动mock服务器\n```javascript\n// start.js\nconst { createServer } = require('egg-thrift-mock');\n\n/* 配置示例\n  {\n    TSayHelloService: {\n      idl: 'test/thrift/hello/hello.thrift',\n      service: require('./thrift/hello/gen-nodejs/TSayHelloService'),\n      port: 9903\n    },\n  }\n*/\nlet cfgs = require('./config');\n\nif (typeof cfgs === 'string') {\n  cfgs = JSON.parse(cfgs);\n}\n\ncreateServer(cfgs);\n```\n\n### 方式二：作为egg插件使用全局对象\n```javascript\n// app/controller/thrift.js\nmodule.exports = app =\u003e class ThriftController extends app.Controller {\n  async test() {\n    const result = await app.thriftMocker.request('TGatewayCityMappingService', 'getMtCityIdByDpCityId');\n\n    const { ctx } = this;\n    ctx.status = 200;\n    ctx.body = {\n      success: true,\n      data: result.data\n    };\n  }\n};\n```\n\n### 方式三：作为egg插件做中间件使用\n拦截请求，直接请求以下格式url即可。\nurl举例：\n```javascript\nconst mockUrl = `http://${localhost}/thrift-mock/${serviceName}/${methodName}`\n```\n\n### 方式四：自定义数据mock方法\n支持mock规则自定义。\n使用方法详见`example/custom-mock-example.js`。\n\n## 其他\n**欢迎各类纠错和补充。谢谢大家~**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikooo%2Fthrift-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkikooo%2Fthrift-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikooo%2Fthrift-mock/lists"}