nyambati/express-acl

No base url

Closed this issue · 3 comments

/**
   * Now lets include our router to the main app
   * Make sure that your app has the base url, e.g. /api/ or /v1
   * nacl will detect your resource based on this url.
   */

What if I prefer no base url?

To make it work, I have to do this in helper.js:

resource: function(next, url) {
      var arr = url.match(/([A-Z])\w+/gi);
      if (!arr) {
        return next();
      } else {
        return arr[0];
      }
    }

Express API best practice requires you specify a base URL to differentiate between front-end and back-end routes. However since not all prefer using base URL this can be done through the config by setting property baseUrl to false as compared to the above approach. This will cater for when base URL is specified.

acl.config ({
      baseUrl: false
});

Using these property we can return the appropriate resource in each scenario.

@kahwooi You can now specify your baseUrl in the config as follows

// if you have a base url 'api'
acl.config({
   baseUrl:'api'
});

// if not you can specify baseUrl as '/' or ignore the config entirely
acl.config();

// or 

acl,config({
   baseUrl: '/'
});

hope that works well for you, thanks for raising the issue