This forum has moved, please join us on github discussions. We will keep these old posts available for reference. Thank you!

Apostrophe 2.11.0 released: support for middleware in any module

You can now add middleware to your Apostrophe site via any module in your project. Just add an self.expressMiddleware method to your module, which takes the usual req, res, next arguments. Or, if it’s more convenient, set self.expressMiddleware to an array of such functions. “Module middleware” is added immediately after the minimum required Apostrophe middleware (bodyParser, req.data, etc), and before any routes.

Note that the apostrophe-express module will automatically find these methods in your modules. This allows you to keep that code close to what is most relevant to it.

Of course there is still a middleware option to the apostrophe-express module which accepts an array of middleware functions as well.