Koa is essentially just an object containing an array of middleware generator functions. Middlewares is how you can really customize your Koa apps. Very pluggable since it works in a stack-like manner. It makes architecting your backend super fun!
You can inject middlewares by simply using .use()
.
Remember that Koa works in a stack-like manner so the order of where you put the middleware in your code matters!
You can move onto the next middleware in line by:
yield next;
You can see the cascading effect of how Koa's middlewares goes downstream then back upstream:
Build your own error handler utilizing this down/up stream behavior of Koa middlewares!
Check out some cool middlewares for Koa here.
Prev: Directory Structure | Next: Routes | Home: Lecture Outline