Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access express app in LoopBack 4 to add middleware

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()?

like image 568
nflaig Avatar asked Dec 22 '25 16:12

nflaig


2 Answers

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.

like image 58
Rifa Achrinza Avatar answered Dec 24 '25 06:12

Rifa Achrinza


LoopBack 4 does not have a first-class support for Express middleware yet, please join the discussion in the following GitHub issue:

  • https://github.com/strongloop/loopback-next/issues/1293

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:

  • Creating an Express Application with LoopBack REST API
like image 44
Miroslav Bajtoš Avatar answered Dec 24 '25 08:12

Miroslav Bajtoš



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!