Search code examples
javascriptregexnode.jsexpressacl

ACL express.js allow role access to subpaths


I'm using following implementation of ACL for my express.js application: https://www.npmjs.com/package/acl

Is there any way to give access to given role for all subpaths of specified path?

    acl.allow([{
        roles: ['admin'],
        allows: [
            { resources: '/admin/*', permissions: '*' },
        ]
    }
]);

is not working for me


Solution

  • It works like this:

    acl.allow([{
      roles  : ['admin'],
      allows : [
        { resources: '/admin', permissions: '*' },
      ]
    }]);
    

    Combined with having the middleware only look at the first part of the URL:

    app.use('/admin', acl.middleware(1), ... });
    

    This basically implements a check that would allow the role admin to access any URL that is prefixed by /admin