{"id":14989354,"url":"https://github.com/chenshenhai/koajs-design-note","last_synced_at":"2025-04-04T23:08:00.621Z","repository":{"id":41247944,"uuid":"129116180","full_name":"chenshenhai/koajs-design-note","owner":"chenshenhai","description":"《Koa.js 设计模式-学习笔记》已完结 😆","archived":false,"fork":false,"pushed_at":"2020-11-12T02:16:39.000Z","size":805,"stargazers_count":666,"open_issues_count":1,"forks_count":133,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T22:12:26.360Z","etag":null,"topics":["koa","koa2","koajs"],"latest_commit_sha":null,"homepage":"https://chenshenhai.github.io/koajs-design-note","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenshenhai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-11T15:36:27.000Z","updated_at":"2025-03-03T13:13:31.000Z","dependencies_parsed_at":"2022-08-10T01:43:21.441Z","dependency_job_id":null,"html_url":"https://github.com/chenshenhai/koajs-design-note","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/chenshenhai%2Fkoajs-design-note","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenshenhai%2Fkoajs-design-note/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenshenhai%2Fkoajs-design-note/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenshenhai%2Fkoajs-design-note/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenshenhai","download_url":"https://codeload.github.com/chenshenhai/koajs-design-note/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261604,"owners_count":20910108,"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":["koa","koa2","koajs"],"created_at":"2024-09-24T14:18:11.543Z","updated_at":"2025-04-04T23:08:00.604Z","avatar_url":"https://github.com/chenshenhai.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Koa.js 设计模式-学习笔记\n\n## 关于本书\n\n![koajs-design-note mini](https://user-images.githubusercontent.com/8216630/42525467-ceea9f42-84a5-11e8-9f3f-9ce358952a51.png)\n\n- [关于作者(我)](https://chenshenhai.com/)\n- 个人博客阅读入口 [https://chenshenhai.com/koajs-design-note](https://chenshenhai.com/koajs-design-note);\n- Github Pages 阅读入口 [https://chenshenhai.github.io/koajs-design-note/](https://chenshenhai.github.io/koajs-design-note/)\n- 如有错误或疑问欢迎，提交[issues](https://github.com/chenshenhai/koajs-design-note/issues)或PR\n\n\n更多前端`技术学习`和`开源学习教程`可关注公众号 `DeepSeaCode`  (`大海码` ) \n\n![qrcode_for_gh_959d1c4d729a_258](https://user-images.githubusercontent.com/8216630/43264303-495bf52c-9118-11e8-85cd-4ec6fcc6d066.jpg)\n\n\u003cbr/\u003e\n\n\n## 前言\n\n之前写过一本 [《Koa2进阶学习笔记》](https://github.com/chenshenhai/koa2-note) 作为Koa的入门教程。很多知识点都是一笔带过，没有深入的讲解。这一本书是通过Koa.js的常用中间件实现原理，举一反三来讲解一些Node.js在Web开发过程中的原理和设计模式。\n\n\nKoa.js 是一个极其精简的Web框架，只提供一下两种功能：\n\n- HTTP服务\n    - 处理HTTP请求request\n    - 处理HTTP响应response\n- 中间件容器\n    - 中间件的加载\n    - 中间件的执行\n\n剩下的其他Web服务所需的能力，就根据开发者的需求去自定义开发，留下了很大的灵活空间，提高了Web服务的开发成本。在我的理解中，Koa.js的灵活度带来的开发成本有以下两种：\n\n- 框架的设计\n- 中间件的选择\n\n框架的设计，这一因素比较复杂，后续会新开一本书讲解。本书主要是解析常用的Koa.js中间件，抽象出相关中间件的功能原理和实现方式，用demo让读者理解原理，减少对官方源码的依赖，尽量达到“授人予渔”。\n\n\n\n## 目录\n\n\n* 1. Koa.js 原理\n    * [1.1 学习准备](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/01.md)   \n    * [1.2 Promise 使用](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/02.md)\n    * [1.3 async/await 使用](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/03.md)\n    * [1.4 Node.js原生http模块](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/04.md)\n    * [1.5 中间件引擎](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/05.md)\n    * [1.6 普通中间件式HTTP服务实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/06.md)\n    * [1.7 最简Koa.js实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter01/07.md)\n* 2. Koa.js 的AOP设计\n    * [2.1 AOP面向切面编程](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter02/01.md)\n    * [2.2 洋葱模型切面](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter02/02.md)\n    * [2.3 HTTP切面流程](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter02/03.md)\n* 3. Koa.js 中间件\n    * [3.1 中间件分类](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter03/01.md)\n    * [3.2 狭义中间件](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter03/02.md)\n    * [3.3 广义中间件](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter03/03.md)\n* 4. 狭义中间件-请求/响应拦截\n    * [4.1 koa-logger 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter04/01.md)\n    * [4.2 koa-send 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter04/02.md)\n    * [4.3 koa-static 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter04/03.md)\n* 5. 狭义中间件-context代理\n    * [5.1 koa-view 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter05/01.md)\n    * [5.2 koa-jsonp 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter05/02.md)\n    * [5.3 koa-bodyparser 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter05/03.md)\n* 6. 广义中间件-间接中间件处理\n    * [6.1 koa-router 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter06/01.md)\n    * [6.2 koa-mount 实现](https://github.com/chenshenhai/koajs-design-note/tree/master/note/chapter06/02.md)\n    \n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenshenhai%2Fkoajs-design-note","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenshenhai%2Fkoajs-design-note","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenshenhai%2Fkoajs-design-note/lists"}