strongloop / strong-remoting

Communicate between objects in servers, mobile apps, and other servers.
www.strongloop.com
Other
105 stars 93 forks source link

Regex support for remote hooks declarations #340

Closed superkhau closed 6 years ago

superkhau commented 8 years ago

As an end user, I would like to use regular expressions to match multiple remote methods.

For example:

module.exports = function(Payment) {
  Payment.helloRemote = function(msg, cb) {
    cb(null, 'hello');
  };
  Payment.remoteMethod('helloRemote', {
    accepts: {arg: 'msg', type: 'string'},
    returns: {arg: 'greeting', type: 'string'}
  });

  Payment.worldRemote = function(msg, cb) {
    cb(null, 'world');
  };
  Payment.remoteMethod('worldRemote', {
    accepts: {arg: 'msg', type: 'string'},
    returns: {arg: 'greeting', type: 'string'}
  });

  Payment.afterRemote('*Remote', function(ctx, user, next) {
    console.log('wildcard triggered');
    next();
  });
};

The current workaround is to use ctx.method.name to check if the remote method needs triggering:

Payment.afterRemote('*', function(ctx, user, next) {
  var ignoreList = ['helloRemote', 'worldRemote'];
  if (ignoreList.indexOf(ctx.method.name)) return next();

  // do something
  next();
});
superkhau commented 8 years ago

@bajtos This is probably just be a one off case for a customer request and I believe the workaround should be good enough for now. Feel free to plan accordingly as you see fit as this is probably a good feature to have in general.

bajtos commented 6 years ago

With the release of LoopBack 4.0 GA (see the announcement), this module has entered Active LTS mode and no longer accepts new features (see our LTS policy).