๐ Introduction to Middleware
A middleware is a function that takes a context, and a function that will apply the next middleware. It is a good idea to use the async keyword for these functions so you can use await.
Sunder ships with some middleware, it is up to you to compose them. For any non-trivial app you should use the Router middleware.
Example one: Middleware that logs all requests#
Example two: Middleware that prints all errors to console#
Further reading#
- A blogpost about Koa middleware chaining: Sunder uses the exact same mechanisms as Koa.