Devendra Verma
Devendra Verma

Reputation: 1015

Disable blueprint routes sails js

Hello I have model users, in which there is a foreign key of Orders model. Now sails will automatically generate route /users/:id/orders. I have to disable this route. How to do this ? I have already tried to disable all routes of orders using: _config : { actions: false, rest: false, shortcuts: false } but it still doen't work

Upvotes: 1

Views: 539

Answers (2)

alejdg
alejdg

Reputation: 2473

You could control the access to this model through policies.

For blocking everything put the code below inside your /config/policies.js file:

Orders : {
  '*': false
},

You could also overwrite the route In /config/routes.js:

'/:collection/:id/:model': {response: 'forbidden'}

Or you could do the way you've done, disabling the rest routes on this model

Just make sure you put the whole block, including the export line:

module.exports = {
  _config: {
    rest: false
  }
}; 

Upvotes: 0

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

You can achieve this by adding custom routes, which will overwrite the blueprint action.

Use http://sailsjs.org/documentation/concepts/routes/custom-routes#?response-target-syntax

'/users/:id/orders': {response: 'forbidden'}

or http://sailsjs.org/documentation/concepts/routes/custom-routes#?function-target-syntax

'/users/:id/orders': function(req, res) {res.forbidden();}

Upvotes: 2

Related Questions