https://github.com/bpcloud/middleware
https://github.com/bpcloud/middleware
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bpcloud/middleware
- Owner: bpcloud
- Created: 2021-03-11T03:01:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T10:08:53.000Z (12 months ago)
- Last Synced: 2025-02-02T13:15:02.969Z (11 months ago)
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# bpframework Middleware specification
The middleware must have below methods:
```js
interface BpframeworkMiddleware {
/** name of middleware */
name: string,
/** web framework type. e.g. 'koa' **/
type: string,
/** initiator the middleware */
initiator: (app:any, bpApp:any)=>void,
/** The framework context finished, all objects of framework, e.g. FeignClient, start working. */
contextFinished?: (app:any, bpApp:any)=>void,
/** call before route */
beforeRoute?: (app:any, bpApp:any, request?:any)=>Promise,
/** call after route */
afterRoute?: (app:any, bpApp:any)=>Promise,
}
```
`initiator` -> `contextFinished` -> `beforeRoute` -> `afterRoute`
Example:
```js
export default {
name: 'test-middleware',
type: 'koa',
initiator(app, bpApp) {
},
async beforeRoute(ctx, bpApp, request): boolean {
// To interrupt process of follow-up .
return false;
},
async afterRoute(ctx, bpApp): boolean {
// To interrupt process of follow-up.
return false;
},
}
```
### List
| name | descs |
| -------------- | ---------------------------------------------------- |
| koa-i18n | https://github.com/bpcloud/middleware-koa-i18n |
| koa-bodyparser | https://github.com/bpcloud/middleware-koa-bodyparser |
| koa-cors | https://github.com/bpcloud/middleware-koa-cors |
| koa-session | https://github.com/bpcloud/middleware-koa-session |
| redis | https://github.com/bpcloud/middleware-redis |