照着官方的示例打算入门 egg 结果我简单的修改了下代码,就运行到 nofound middleware 里面去了。 router 肯定没问题,试试了去掉了自定义的 error_handler middler就正常了,但是肯定不是这个问题,代码很简单。 代码地址
error_handler
求有明白的指导下原因。
问题原因:error_handler 用法错误
Egg.js 是兼容 Koa 1.x 和 2.x 支持的所有形式的中间件,文档 https://eggjs.org/zh-cn/basics/middleware.html#使用-koa-的中间件 Koa的中间 async 的写法是: async function: async (ctx, next) => {}
async (ctx, next) => {}
你这边是: https://github.com/elevensky/egg-example/blob/master/app/middleware/error_handler.js#L2 所以这样写是错误的, next 也要写成 next()
谢谢,好了
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
问题原因:error_handler 用法错误
Egg.js 是兼容 Koa 1.x 和 2.x 支持的所有形式的中间件,文档 https://eggjs.org/zh-cn/basics/middleware.html#使用-koa-的中间件 Koa的中间 async 的写法是: async function:
async (ctx, next) => {}你这边是: https://github.com/elevensky/egg-example/blob/master/app/middleware/error_handler.js#L2 所以这样写是错误的, next 也要写成 next()
谢谢,好了