Skip to content

Config options - disable UI, disable Swagger #51

Closed
strongloop/loopback-boot
#168

Description

@bajtos

There should be an easy way how to disable explorer (either UI only or everything) when running in production.

A possible solution: add two new properties to the option object used by middleware factory function.

These two new properties then can be configured either from server/boot/explorer.js, or using the upcoming component infrastructure (see https://github.com/strongloop/loopback-example-component/wiki).

Activity

  1. ricardohbin commented on Nov 19, 2014

    @ricardohbin

    +1

  2. oakley808 commented on Jan 21, 2015

    @oakley808

    +1

  3. bajtos commented on Jan 21, 2015

    @bajtos
    MemberAuthor

    @ricardohbin @oakley808 Can you contribute this feature yourself?

  4. bajtos commented on Mar 2, 2015

    @bajtos
    MemberAuthor

    On the second thought, I don't think it makes sense to disable the UI while keeping the Swagger metadata available. With metadata available, one can run an own copy of the Swagger UI (e.g. via http://petstore.swagger.io/) and configure it with the Swagger metadata provided by the LoopBack server.

    See also strongloop/loopback#1134, it points out a similar problem.

    Here is the solution I would like to see implemented instead: extend loopback-boot's support for component-config.json (see strongloop/loopback-boot#86) to allow developers to enable/disable components on per-environment basis.

    At the moment, explorer can be configured as follows:

    // server/component-config.json
    {
      "loopback-explorer": {
        // config
      }
    }

    We need to extend loopback-boot so that a component like loopback-explorer can be disabled in production via the following JSON file:

    // server/component-config.production.json
    {
      "loopback-explorer": null
    }

    @raymondfeng Thoughts? This is similar to (but not the same as) the way how middleware can be disabled on per-environment basis via server/middleware.production.json. I am also aware that this feature is useful for 2.x only, as strongloop/loopback-boot#93 will obsolete it.

    /cc @PradnyaBaviskar

  5. raymondfeng commented on Mar 2, 2015

    @raymondfeng
    Member

    @bajtos With your proposal, do we need to change the loopback-explorer code to accept the config object and decide if itself should be disabled?

  6. bajtos commented on Mar 2, 2015

    @bajtos
    MemberAuthor

    No, loopback-explorer does not need to be changed, this feature will be handled by loopback-boot. That's why I am proposing loopback-explorer: null as opposed to loopback-explorer: { enabled: false }.

  7. raymondfeng commented on Mar 2, 2015

    @raymondfeng
    Member

    OK, so if loopback-explorer: null or loopback-explorer: false is configured, loopback-boot doesn't even bother to load the loopback-explorer component, right? If so, I'm +1.

    BTW, we should consider to use this convention to remove/disable properties inherited from base models.

  8. bajtos commented on Mar 2, 2015

    @bajtos
    MemberAuthor

    OK, so if loopback-explorer: null or loopback-explorer: false is configured, loopback-boot doesn't even bother to load the loopback-explorer component, right? If so, I'm +1.

    Yes, that's the plan

    BTW, we should consider to use this convention to remove/disable properties inherited from base models.

    I am fine with that, thought it's completely out of scope of this issue.

  9. ricardohbin commented on Mar 2, 2015

    @ricardohbin

    surely @bajtos, I can give a look at this ;)

  10. self-assigned this
    on Mar 10, 2015
  11. bajtos commented on Mar 10, 2015

    @bajtos
    MemberAuthor

    The loopback-boot change has been landed via strongloop/loopback-boot#103, let me know if it works for you.

  12. voitau commented on Oct 25, 2015

    @voitau

    Tried to use as suggested in documentation:

    {
      "loopback-component-explorer": false
    }
    

    Works if no overrides. If original component-config.json has any configuration options defined, then override with false fails and the app exits. Does anyone else experience the same issue?

  13. bajtos commented on Nov 6, 2015

    @bajtos
    MemberAuthor

    @voitau Works if no overrides. If original component-config.json has any configuration options defined, then override with false fails and the app exits. Does anyone else experience the same issue?

    This is off-topic for this GH issue. Please open a new issue for the problem and provide steps for reproducing the issue on our machines, see wiki.

  14. faridnsh commented on Dec 28, 2015

    @faridnsh

    This is still an issue because setting loopback-explorer: null or loopback-explorer: false in component-config.production.json doesn't override loopback-explorer: { ... }.

    Here's a test for loopback-boot to replicate the issue:

    diff --git a/test/executor.test.js b/test/executor.test.js
    index 52564af..a6f716b 100644
    --- a/test/executor.test.js
    +++ b/test/executor.test.js
    @@ -756,6 +756,24 @@ describe('executor', function() {
           appdir.resolve('components/test-component/index.js'));
       });
    
    +  it('disable component if overrided by production configuration', function() {
    +    appdir.writeConfigFileSync('component-config.json', {
    +      './components/test-component': {}
    +    });
    +    appdir.writeConfigFileSync('component-config.production.json', {
    +      './components/test-component': null
    +    });
    +
    +    appdir.writeFileSync('components/test-component/index.js',
    +      'module.exports = ' +
    +      'function(app, options) { app.componentOptions = options; }');
    +
    +    boot(app, { appRootDir: appdir.PATH, env: 'production' });
    +
    +    expect(Object.keys(require.cache)).to.not.include(
    +      appdir.resolve('components/test-component/index.js'));
    +  });
    +
       it('configures middleware (that requires `this`)', function(done) {
         var passportPath = require.resolve('./fixtures/passport');
    
  15. bajtos commented on Jan 7, 2016

    @bajtos
    MemberAuthor

    @alFReD-NSH This is still an issue because setting loopback-explorer: null or loopback-explorer: false in component-config.production.json doesn't override loopback-explorer: { ... }.

    Could you please open an issue in loopback-boot? Submitting a patch fixing the issue would be even better :)

  16. faridnsh commented on Jan 8, 2016

    @faridnsh

    There's already in an issue opened there: strongloop/loopback-boot#146

    I'll be submitting a pr soon.

  17. added a commit that references this issue on Jan 8, 2016
    d850560
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions