Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to migrate (app-level) Express middleware from LB3 to LB4 #3947

Closed
3 tasks
bajtos opened this issue Oct 17, 2019 · 3 comments
Closed
3 tasks

How to migrate (app-level) Express middleware from LB3 to LB4 #3947

bajtos opened this issue Oct 17, 2019 · 3 comments

Comments

@bajtos
Copy link
Member

bajtos commented Oct 17, 2019

This is a follow-up for #3718 and #3922.

Write content for docs/site/migration/express-middleware.md, explain how to modify a LB4 app with a mounted LB3 app to share the same Express middleware.

Initial setup:

lb4-app
 - lb3-app
   - Express middleware

The idea is to create a new top-level Express app, where we can mount the middleware to get it executed for requests handled by both LB3 and LB4 routes.

express app
 - Express middleware
 - lb4-app
   - lb3-app

Acceptance criteria

@bajtos
Copy link
Member Author

bajtos commented Nov 5, 2019

The idea is to create a new top-level Express app, where we can mount the middleware to get it executed for requests handled by both LB3 and LB4 routes.

Such setup is documented here: https://loopback.io/doc/en/lb4/express-with-lb4-rest-tutorial.html

In the migration guide, we need to describe how to apply the steps outlines in "Creating an Express Application with LoopBack REST API" to an application created by following the steps in Mounting a LoopBack 3 application.

Note that in LB3, we are using declarative approach to middleware registration (see server/middleware.json). In Express+LB4+LB3 scenario, middleware is registered programmatically from JS/TS code.

/cc @hacksparrow

@dhmlau
Copy link
Member

dhmlau commented Dec 11, 2019

#4056 has landed. Closing as done.

@victor-enogwe
Copy link

In case anyone needs this, the concept of interceptors solved this for me. to simulate a global app.use like in express I made a global interceptor. For middlewares scoped to class methods(controllers) create local interceptors and decorate your controller methods with the @intercept decorator function. See an example loopback-next helmet middleware here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants