I've got a few middlewares in my app:
loggedInUserHandler
: Loads the current user and saves it the contextnotificationHandler
: Gets the current user from the context. Then loads the notifications for this user and saves them to the context.routeHandler
: Gets the current user and notifications from the context, and loads it into the correct view.
Basically each middleware might depend on the data that previous middlewares produce and attach to the context. For now, I'm simply loading the middlewares in the correct order, like so:
app.use(loggedInUserHandler);
app.use(notificationHandler);
app.use(routeHandler);
However I wonder if there's a better way to do this and perhaps declare the dependencies of each middleware? Then if they are called in the wrong order, an error would be thrown or something similar. I couldn't find much info about this in Koa so I'm wondering if there's a proper way to do it. Any suggestion?