Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rrd-fe/koa2-reference
A simple Koa2 library implemention
https://github.com/rrd-fe/koa2-reference
koa2 nodejs typescript
Last synced: about 1 month ago
JSON representation
A simple Koa2 library implemention
- Host: GitHub
- URL: https://github.com/rrd-fe/koa2-reference
- Owner: rrd-fe
- Created: 2019-09-15T01:21:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-15T14:38:16.000Z (about 5 years ago)
- Last Synced: 2024-08-02T13:32:24.183Z (4 months ago)
- Topics: koa2, nodejs, typescript
- Language: TypeScript
- Size: 13.7 KB
- Stars: 9
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-luooooob - rrd-fe/koa2-reference - A simple Koa2 library implemention (TypeScript)
README
# koa2-typescript-reference
A simple Koa2 library implementation written by TypeScript, show you the kernel of Koa2 and how to step by step write a Koa2.
## Get Start
Koa 类库的几个核心特点 :
* 中间件洋葱圈模型
* context封装
* try catch 错误处理能力详细实现[参考文章](https://github.com/rrd-fe/blog/blob/master/nodejs/koa2-implementation.md)
下面我们拆分成四步实现一个简易的Koa框架:
### Step 1 基础Server运行
* 目标:提供Koa类,支持通过listen启动Server,use添加一个类中间件处理函数
* 运行:npm run start:1### Step 2 洋葱圈中间件机制实现
* 目标:支持use添加多个中间件,并按照洋葱圈模式调用
* 运行:npm run start:2### Step 3 context提供
* 目标:封装request、response,提供context对象贯穿所有中间件调用
* 运行:npm run start:3### Step 4 同步错误处理能力
* 目标:支持错误监听(app.on('error')),支持通过try catch进行一场捕获
* 运行:npm run start:4### Step 5 拆分Request、Response、Context增加实体类
* 目标
拆分Request、Response、Context增加实体类
Context增加Cookie处理能力* 运行: npm run start:6
### Step 6 增加Session中间件
* 目标
增加 session中间件,支持ctx.session操作session数据
增加 request 增加 query参数* 运行: npm run start:6