Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lq782655835/build-your-own-koa
简短实现koa库
https://github.com/lq782655835/build-your-own-koa
code koa2
Last synced: 19 days ago
JSON representation
简短实现koa库
- Host: GitHub
- URL: https://github.com/lq782655835/build-your-own-koa
- Owner: lq782655835
- Created: 2020-06-14T15:28:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-14T15:32:49.000Z (over 4 years ago)
- Last Synced: 2024-11-22T03:27:36.750Z (3 months ago)
- Topics: code, koa2
- Language: JavaScript
- Size: 230 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# build-your-own-koa
koa核心2点: 1. 中间件模式 2. 洋葱模型
## 中间件模式
中间件ctx实现核心:
``` js
createContext(req, res) {
let ctx = this.context
// 原生req/res
ctx.req = req // ctx.req.url
ctx.res = resctx.request = this.request // ctx.request.url
ctx.response = this.responsectx.request.req = req // ctx.request.req.url
ctx.response.res = resreturn ctx
}
```## 洋葱模型
待更新compose