Skip to content

koa 搭建后台服务 ​

全局异常处理 ​

在顶层使用中间件进行异常捕获并处理

ts
import Koa from 'koa'

// exception-handler.ts
export default function exceptionHandler(): Koa.Middleware {
  return async (ctx, next) => {
    try {
      await next()
    } catch (error) {
      // error instanceof xx
      ctx.body = 'do something'
    }
  }
}
// app.ts
app.use(exceptionHandler())

日志处理 log4js ​

JWT 认证 ​

koa-jwt

数据库与 ORM ​

Released under the MIT License.