How can I access the express app instance within a LoopBack 4 application to add a middlware such as helmet or compression via app.use()
?
Asked
Active
Viewed 796 times
3

nflaig
- 673
- 1
- 8
- 15
2 Answers
1
LoopBack 4 does not have a first-class support for Express middleware yet, please join the discussion in the following GitHub issue:
Our current recommendation is to create a top-level Express application (where you can mount middleware like helmet
) and then mount the LoopBack4 application as a sub-component. You can learn more in the following tutorial:

Miroslav Bajtoš
- 10,667
- 1
- 41
- 99
1
Since the previous answer, LoopBack 4 has provided support for Express.js middleware support alongside the existing LoopBack 4 middleware:
- https://loopback.io/doc/en/lb4/Express-middleware.html
- https://loopback.io/doc/en/lb4/Middleware.html
This includes additional features that enable integration with the Context for dependency injection, wrapping the middleware in a factory function for dynamic configuration, and using it as an interceptor.

Rifa Achrinza
- 1,555
- 9
- 19