2024-3-5 nodejs (中间件,中间件的分类,自定义中间件)

45 阅读1分钟

image.png

image.png

image.png

image.png

image.png

image.png

中间件中一定要调用next(),否则无法流转到下一个中间件或路由

image.png

image.png 如图: 这样后续所有的路由中都可以访问中间件的时间,而不需要在每个路由中再写一遍

image.png

image.png

image.png

image.png

image.png

image.png 应用级别中间件(挂载到app身上)

image.png 路由级别中间件(挂载到router对象身上)

image.png 错误级别中间件放在所有路由后面,用于捕获错误,避免系统崩溃

image.png

image.png

image.png