9

I need to override the GET on strongloop. So when I GET foo/ it returns something different as the default one.

I tried using remoteMethod with http: {path: '/', verb: 'get'} without success.

How can I override any default method on strongloop?

perseus
  • 1,322
  • 1
  • 16
  • 22

1 Answers1

13

Finally I found it. So get corresponds to find without any filter.

So the code is:

Foo.on('attached', function() {
  Foo.find = function(filter, callback) {
    //Whatever you need to do here...
    callback(null, {hello: 'hello'});
  }
});

Here there is a link for all the PersistedModel methods

I just put 'attached' without exactly knowing why so if someone can comment the reason it would be great.

perseus
  • 1,322
  • 1
  • 16
  • 22
  • 1
    the `attached` event indicates `Foo` model was attached to the loopback app instance, so you can overwrite at this moment the behaviour of the `find` remote method. Yo can see it on loopback code: https://github.com/strongloop/loopback/blob/6964914bab64496c789c434fec39d2914231ee23/lib/model.js#L73 – Fran Herrero Jul 06 '16 at 15:13