You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow app developers to configure custom Express middleware #1293
Allow Application and Extensions developers to mount Express middleware at application level.
WORKAROUND:
Our current recommendation is to create a top-level Express application (where you can easily mount any middleware) and then mount LB4 as a component (middleware) in that application. See https://loopback.io/doc/en/lb4/express-with-lb4-rest-tutorial.html for detailed instructions.
Acceptance Criteria
A set of APIs allowing Application developers to mount custom Express middleware
A set of APIs allowing Extension developers to contribute Express middleware to target application
Documentation for both App & Extension developers
A clear guidance on how to ensure correct middleware ordering (this may require a spike)
Implementation wise, the piece invoking middleware should be implemented as part of the Sequence handling, so that errors reported by Express middleware are routed to reject action. (For example, we may introduce a new sequence action to be executed before findRoute.)
changed the title [-]Refactor @loopback/rest and @loopback/http-server[/-][+]Allow app developers to configure custom Express middleware[/+]on May 16, 2018
I am proposing to enhance RestServer/RestApplication with an API allowing consumers to mount static files, for example app.static(path, options). This API should leverage Express middleware server-static as an implementation detail.
With this new API in place, we can either write an API Explorer component bundling swagger-ui and calling app.static(pathToSwaggerUI), or preferably write a short guide explaining LB4 users how to add swagger-ui to their project themselves.
Simplifying usage is probably out of scope of GA but I think we should at the very least have some documentation around how a user can add some express middleware to their application (static file serving for example) by overriding the default requestHandler. -- I think that's something important for GA.
I build a loopback component that lets you inject express middleware into the sequence. You can filter it in controllers by using the @middleware('auth') annotation, or you can directly inject middleware into the @middleware(myExpressMiddleware) annotation.
Activity
dhmlau commentedon May 14, 2018
@hacksparrow , is this the same as #1253?
[-]Refactor @loopback/rest and @loopback/http-server[/-][+]Allow app developers to configure custom Express middleware[/+]bajtos commentedon Jun 25, 2018
Related: #559 (comment)
bajtos commentedon Jul 30, 2018
IMO, this is out of 4.0 GA scope as we have defined it. Relabeling this story as post-GA.
virkt25 commentedon Jul 31, 2018
Simplifying usage is probably out of scope of GA but I think we should at the very least have some documentation around how a user can add some express middleware to their application (static file serving for example) by overriding the default
requestHandler. -- I think that's something important for GA.12 remaining items
clayrisser commentedon Jun 21, 2019
I build a loopback component that lets you inject express middleware into the sequence. You can filter it in controllers by using the
@middleware('auth')annotation, or you can directly inject middleware into the@middleware(myExpressMiddleware)annotation.https://github.com/codejamninja/lb4-middleware
raymondfeng commentedon May 12, 2020
Done.
See
https://loopback.io/doc/en/lb4/Middleware.html
https://loopback.io/doc/en/lb4/Express-middleware.html