Skip to content

Allow app developers to configure custom Express middleware #1293

Closed

Description

@hacksparrow

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.)

Out of scope

Activity

  1. self-assigned this
    on Apr 27, 2018
  2. dhmlau commented on May 14, 2018

    @dhmlau
    Member

    @hacksparrow , is this the same as #1253?

  3. changed the title [-]Refactor @loopback/rest and @loopback/http-server[/-] [+]Allow app developers to configure custom Express middleware[/+] on May 16, 2018
  4. added
    RESTIssues related to @loopback/rest package and REST transport in general
    and removed on May 16, 2018
  5. bajtos commented on Jun 25, 2018

    @bajtos
    Member

    Related: #559 (comment)

    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.

  6. bajtos commented on Jul 30, 2018

    @bajtos
    Member

    IMO, this is out of 4.0 GA scope as we have defined it. Relabeling this story as post-GA.

  7. virkt25 commented on Jul 31, 2018

    @virkt25
    Contributor

    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.

  8. 12 remaining items

  9. added and removed on Apr 16, 2019
  10. clayrisser commented on Jun 21, 2019

    @clayrisser
    Contributor

    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

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions