{"id":28406438,"url":"https://github.com/ddzyan/koa-ts","last_synced_at":"2026-04-28T18:02:24.212Z","repository":{"id":42696133,"uuid":"276339769","full_name":"ddzyan/koa-ts","owner":"ddzyan","description":"在 koa 框架上完成三层架构分离，使用 ts 为开发语言，完成依赖注入，装饰器等功能，使koa-ts开发更加快速","archived":false,"fork":false,"pushed_at":"2022-04-12T02:36:07.000Z","size":256,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T08:37:45.514Z","etag":null,"topics":["inject","ioc","koa2","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ddzyan.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":"2020-07-01T09:51:00.000Z","updated_at":"2022-03-27T15:40:55.000Z","dependencies_parsed_at":"2022-09-12T23:12:19.854Z","dependency_job_id":null,"html_url":"https://github.com/ddzyan/koa-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ddzyan/koa-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddzyan%2Fkoa-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddzyan%2Fkoa-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddzyan%2Fkoa-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddzyan%2Fkoa-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddzyan","download_url":"https://codeload.github.com/ddzyan/koa-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddzyan%2Fkoa-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32392304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["inject","ioc","koa2","typescript"],"created_at":"2025-06-01T22:11:17.485Z","updated_at":"2026-04-28T18:02:24.206Z","avatar_url":"https://github.com/ddzyan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 简介\n\n使用 ts + koa2 + 装饰器 完成服务端功能开发\n\n## 核心代码介绍\n\n### Reflect Metadata\n\n资料介绍：https://itdashu.com/docs/typescriptlesson/2edda/reflectmetada.html\n\nReflect Metadata 可以在声明的时候对对象添加元数据。通过这种方式添加对元数据，不会对对象原始对数据结构产生影响\n\n一些基础库源码如 vue-class-component、Angular 均使用了 Reflect Metadata ，有兴趣的可以深入源码学习下。\n\n在使用的时候必须安装此模块\n\n```bash\nnpm i reflect-metadata --save\n```\n\n#### 注意\n\nTIPS: 实例方法与静态方法取元数据是不同的，实例方法需要在类的实例上取元数据，静态方法直接在类上取元数据。\n\n## 完成功能\n\n1. ts + koa 基础框架搭建和配置\n2. 中间件根据配置文件，自动化热加载\n3. 增加 controller，router 装饰器，实现通过装饰器配置路由地址\n\n## 使用\n\n```sh\ngit clone https://github.com/ddzyan/koa-ts.git\n\ncd koa-ts\n\nnpm install\n```\n\n### vsCode 配置\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"name\": \"koa2\",\n      \"type\": \"node\",\n      \"request\": \"launch\",\n      \"program\": \"${workspaceRoot}/src/server.ts\",\n      \"stopOnEntry\": false,\n      \"args\": [],\n      \"cwd\": \"${workspaceRoot}\",\n      \"outFiles\": [\"${workspaceRoot}/dist/**/*.js\"],\n      \"runtimeExecutable\": \"nodemon\",\n      \"runtimeArgs\": [\"--nolazy\"],\n      \"env\": {\n        \"NODE_ENV\": \"development\"\n      },\n      \"sourceMaps\": true,\n      \"restart\": true\n    }\n  ]\n}\n```\n\n### 直接调试 ts\n\n添加 vscode launch.json 文件\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"name\": \"Current TS File\",\n      \"type\": \"node\",\n      \"request\": \"launch\",\n      \"program\": \"${workspaceRoot}/node_modules/ts-node/dist/bin.js\",\n      \"args\": [\"${relativeFile}\"],\n      \"cwd\": \"${workspaceRoot}\",\n      \"protocol\": \"inspector\"\n    }\n  ]\n}\n```\n\n在要调试的文件头部添加 debugger,插入断点并且选择指定的 debug 模式，F5 运行\n\n### 启动\n\n```sh\n# 启动tsc编译监控\nnpm run dev\n```\n\n点击 vscode 默认 debug 键, enjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddzyan%2Fkoa-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddzyan%2Fkoa-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddzyan%2Fkoa-ts/lists"}