loopback-remote-routing
easily disable remote methods
Last updated 3 years ago by neillv .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install loopback-remote-routing 
SYNC missed versions from official npm registry.

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  also need to follow the naming convention
  RemoteRouting(Color, {only: [
      '@find',
      '@findById',
      'updateAttributes',
      '@customRemotemethod',
      'customRemotemethodOnPrototype'
  ]})

  //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

Current Tags

  • 1.5.2                                ...           latest (3 years ago)

17 Versions

  • 1.5.2                                ...           3 years ago
  • 1.5.1                                ...           3 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |