Skip to content

fullcube/loopback-remote-routing

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loopback-remote-routing

Circle CI

Easily disable remote methods.

##Features

  • selectively disable remote methods created by relations, defined by code or in definition
  • selectively disable remote methods created by scopes , defined by code or in definition
  • easily disable custom remote methods, currently works only when use RemoteRouting directly in js file
  • support loopback-component-storage specific methods
  • use as mixin
  • support for loopback@3.x

##Installation

npm install loopback-remote-routing --save

##How to use

###use directly

// common/models/color.js
var RemoteRouting = require('loopback-remote-routing');

module.exports = function(Color) {
  // use only to expose specified remote methods
  // symbol @ denotes static method
  // scope methods are static method
  // custom remote method just need to specify the method name
  RemoteRouting(Color, {only: [
      '@find',
      '@findById',
      'updateAttributes'
      'customRemotemethod'
  ]})

  //use except to expose all remote methods except specified ones
  RemoteRouting(Color, {except: [
      '@create',
      '@find'
  ]}

  //disable all remote methods omitting options

  RemoteRouting(Color)

}

use 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"
        ]
      }
    }
  }

##Options

option type description required
only [String] expose specified remote methods false
except [String] expose all remote methods except specified ones false

You can only use options.only or options.except, do not use them together.

If you don't know the relation methods name , you can read the doc : http://loopback.io/doc/en/lb3/Exposing-models-over-REST.html

##TODO

  • allow disable custom remote methods
  • disable alias remote methods, such as upert, patchOrCreate

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%