Skip to content

Declaratively load loopback.rest and loopback-explorer #75

Closed

Description

@bajtos

In order to remove boot/rest and boot/explorer from the api-server template, we need to extend loopback-boot to support the following features:

  1. Specifying middleware parameters as a value to be read via app.get from config.json, example:

    {
      "routes": {
        "loopback#rest": {
          "paths": ["${restApiRoot}"]
        }
    }
  2. Allowing the middleware to be optional, e.g.

    {
      "routes": {
        "loopback-explorer": {
          "optional": "Run `npm install loopback-explorer` to enable the LoopBack explorer.",
          "params": {
            "basePath": "$!{restApiRoot}"
          }
       }
    }
  3. Rework the explorer so that it can get the app object via req.app on the first request, in the same way as loopback.rest.

Activity

  1. added this to the #Epic: Components milestone on Nov 28, 2014
  2. self-assigned this
    on Nov 28, 2014
  3. raymondfeng commented on Dec 3, 2014

    @raymondfeng
    Member

    I would also need to access the app instance either via the parameter injection or set by boot to the factory/handler instance.

  4. 9 remaining items

  5. bajtos commented on Jun 25, 2015

    @bajtos
    MemberAuthor

    @hacksparrow I am afraid your proposal above goes against the original intention of this issue, which is to "Rework the explorer so that it can get the app object via req.app on the first request, in the same way as loopback.rest." I personally think it's a bad practice for middleware to expect the app object in factory arguments, it should get the app it's mounted on via req.app.

    However, per the discussion in strongloop/loopback-component-explorer#21, I believe the agreed way forward is to rework loopback-explorer into a component. I'll take a close look on this tomorrow (CEST).

  6. hacksparrow commented on Jun 25, 2015

    @hacksparrow
    Member

    Thanks for the feedback @bajtos, will change accordingly.

  7. hacksparrow commented on Jul 16, 2015

    @hacksparrow
    Member

    @bajtos per this example:

    {
      "routes": {
        "loopback#rest": {
          "paths": ["${restApiRoot}"]
        }
    }
    

    We will now call loopback.rest() directly via a configuration in middleware.json, instead of using server/boot/rest-api.js, and therefore make the necessary changes to loopback/server/middleware/rest.js to enable this, right?

  8. bajtos commented on Aug 5, 2015

    @bajtos
    MemberAuthor

    We will now call loopback.rest() directly via a configuration in middleware.json, instead of using server/boot/rest-api.js

    Yes please.

    therefore make the necessary changes to loopback/server/middleware/rest.js to enable this, right?

    I am not aware of any changes that are necessary, could you please elaborate little bit more?

  9. bajtos commented on Aug 5, 2015

    @bajtos
    MemberAuthor

    therefore make the necessary changes to loopback/server/middleware/rest.js to enable this, right?

    Did you mean implementing necessary changes to support "paths": ["${restApiRoot}"]? That should be implemented in loopback-boot's lib/executor.js

  10. hacksparrow commented on Aug 12, 2015

    @hacksparrow
    Member

    Thanks for the info @bajtos.

    Another thing; what would be the interface for doing something like this?

    var websitePath = require('path').resolve(__dirname, '../client');
    app.use(loopback.static(websitePath));
    
  11. bajtos commented on Aug 12, 2015

    @bajtos
    MemberAuthor
    var websitePath = require('path').resolve(__dirname, '../client');
    app.use(loopback.static(websitePath));

    Assuming __dirname is pointing to the same directory where server/middleware.json is, then you can achieve the same result using the following entry in server/middleware.json file:

    {
      "files": {
        "loopback#static": {
          "params": "$!../client"
        }
      }
    }
  12. hacksparrow commented on Aug 13, 2015

    @hacksparrow
    Member

    @bajtos opened a PR to declaratively load loopback.rest - #149. However, there is a bunch of build errors triggered by some pre-existing code, I can fix it if I get the go-ahead. Please review and let me know.

  13. hacksparrow commented on Aug 13, 2015

    @hacksparrow
    Member

    Also, are we not supporting const yet?

  14. hacksparrow commented on Aug 13, 2015

    @hacksparrow
    Member

    @bajtos is there a reason why loopback#rest takes an array of paths while loopback-explorer takes a single mountPath?

  15. crandmck commented on Aug 26, 2015

    @crandmck

    @bajtos Can this be closed with the merging of #149?

    If not, what are the remaining items to complete before this can be closed?

  16. hacksparrow commented on Aug 27, 2015

    @hacksparrow
    Member

    @crandmck component-config.json should parse ${var} too. I have gotten it to parse, but still working on a way for explorer to be loaded declaratively and replicate its current behavior.

    With explorer loading as intended, we can close this.

  17. bajtos commented on Aug 27, 2015

    @bajtos
    MemberAuthor

    @crandmck as @hacksparrow wrote, we need to land one more change to loopback-boot and then rework the example app to load the explorer component declaratively.

    @hacksparrow don't worry about reproducing exactly same behaviour. The important part is to print the explorer URL on start. The support for explorer being an optional dependency can be dropped and explorer can become a proper (required) dependency.

  18. hacksparrow commented on Sep 5, 2015

    @hacksparrow
    Member

    @bajtos @crandmck I guess we can close this now?

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions