{"id":20542207,"url":"https://github.com/weivea/fastify-service","last_synced_at":"2026-05-29T08:32:16.555Z","repository":{"id":83302247,"uuid":"126985270","full_name":"weivea/fastify-service","owner":"weivea","description":"在复杂业务场景下用于做业务逻辑封装的一个抽象层, 保持业务逻辑的独立性","archived":false,"fork":false,"pushed_at":"2018-03-27T12:48:33.000Z","size":2,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T04:29:25.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/weivea.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-27T12:48:01.000Z","updated_at":"2020-07-10T06:43:22.000Z","dependencies_parsed_at":"2023-07-08T03:00:19.642Z","dependency_job_id":null,"html_url":"https://github.com/weivea/fastify-service","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/fastify-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/fastify-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33644285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-16T01:29:48.064Z","updated_at":"2026-05-29T08:32:16.538Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastiy-servise\n\nfastiy-servise 为control提供service，  \n用法类似 egg 的service, **兼容egg service 写法**\n就不用再把臃肿的代码写在 control里边了\n\nservice下的方法 可以通过`this.ctx.servics.xxx` 或 `this.request.servics.xxx` 相互调用，  \n`this.request`即为每次请求的 request\n\n支持`async/await`方法\n\n\n## install\n\n```\nnpm install fastiy-servise --save\n```\n\n## usage\n\n\nindex.js\n```javascript\nconst service = require('fastify-service')\nconst fastify = require('fastify')()\nfastify.register(service, {\n    serviceRoot: path.join(process.cwd(), 'service/')\n  })\napp.get('/api', async (req, res) =\u003e {\n    req.service.testb.bFun()\n    req.service.aa.funA()\n    await req.service.testb.b2Fun()\n    return {\n      hello: 'ServerData'\n    }\n  })\n\n```\n\nservice目录\n```\n.\n./aa.js\n./testa\n./testa/testd.js\n./testa.js\n./testb.js\n./testc\n./testc/testc.js\n```\n\n./testb.js\n```javascript\nclass Servic {\n  bFun() {\n    // service之间相互调用\n    this.ctx.service.testc.testc.bFun()\n    console.log(__filename);\n    return __filename;\n  }\n  async b2Fun() {\n    return await (() =\u003e\n      new Promise((resolve, reject) =\u003e {\n        // 自运行返回Promise\n        setTimeout(() =\u003e {\n          console.log('async', __filename)\n          resolve(__filename);\n        }, 500);\n      }))();\n  }\n}\n\nmodule.exports = Servic;\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Ffastify-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-service/lists"}