loopback-remote-routing Easily disables Remote methods

153 views
Skip to first unread message

吕锦昂

unread,
Nov 20, 2015, 4:15:46 AM11/20/15
to loopb...@googlegroups.com
Hi all, 

I just create a module to easily disable remote methods, https://www.npmjs.com/package/loopback-remote-routing. 

once before, if we want to disable remote methods, we have to write a bunch of statements like this:

User.disableRemoteMethod('create', true);
User.disableRemoteMethod('__get__items', false);
User.disableRemoteMethod('findById', true);


using loopback-remote-routing, what you have to do, is simply passing some options

var RemoteRouting = require('loopback-remote-routing');

//use options.only to expose specifed remote methods;
//in this case only create, findById, __get__items will be exposed
RemoteRouting(User, {only: [
    '@create',
    '@findById',
   '__get__items'
]}

//use options.except to expose all remote methods except ones specified;
// in this case, findById, create, __get__items, will be disabled
RemoteRouting(User, {except: [
    '@create',
    '@findById',
   '__get__items'
]}

it can also be used as a mixin:

Add the mixins property to your server/model-config.json like the following:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-remote-routing",
      "../common/mixins"
    ]
  }
}

To use with your Models add the mixins attribute to the definition object of your model config.

  {
    "name": "Color",
    "properties": {
      "name": {
        "type": "string",
      }
    },
    "mixins": {
      "RemoteRouting" : {
        "only": [
          "@find"
        ]
      }
    }
  }

welcome to open issues if you have any questions


吕锦昂

unread,
Mar 22, 2016, 5:18:47 AM3/22/16
to LoopbackJS
This module is useful if you are developing apis.
Reply all
Reply to author
Forward
0 new messages