最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disabling default sails.js routes - Stack Overflow

programmeradmin3浏览0评论

I'm setting up a basic Sails.js app, and I'm trying to disable the default routing system in sails.js. The documentation here seems to indicate it can be disabled in the /config/blueprints.js file, by setting module.exports.blueprints = { actions: false };

However, when I do sails lift, I'm still able to access my default controller at /foo

Edit: This is using Sails v0.10.5, with no changes other than the two files below.

/**   /api/controllers/FooController.js **/
module.exports = {
    index: function(req, res) {
        return res.send("blah blah blah");
    }
};

/**   /config/blueprints.js **/
module.exports.blueprints = {
    actions: false,
    rest: false,
    shortcuts: false,
    prefix: '',
    pluralize: false,
    populate: false,
    autoWatch: true,
    defaultLimit: 30
};

Additionally, the issue continues to occur if I disable blueprints on a per-controller basis:

/**   /api/controllers/FooController.js **/
module.exports = {
    _config: { actions: false, shortcuts: false, rest: false },
    index: function(req, res) {
        return res.send("blah blah blah");
    }
};

The controller is still accessible at /foo

I'm setting up a basic Sails.js app, and I'm trying to disable the default routing system in sails.js. The documentation here seems to indicate it can be disabled in the /config/blueprints.js file, by setting module.exports.blueprints = { actions: false };

However, when I do sails lift, I'm still able to access my default controller at /foo

Edit: This is using Sails v0.10.5, with no changes other than the two files below.

/**   /api/controllers/FooController.js **/
module.exports = {
    index: function(req, res) {
        return res.send("blah blah blah");
    }
};

/**   /config/blueprints.js **/
module.exports.blueprints = {
    actions: false,
    rest: false,
    shortcuts: false,
    prefix: '',
    pluralize: false,
    populate: false,
    autoWatch: true,
    defaultLimit: 30
};

Additionally, the issue continues to occur if I disable blueprints on a per-controller basis:

/**   /api/controllers/FooController.js **/
module.exports = {
    _config: { actions: false, shortcuts: false, rest: false },
    index: function(req, res) {
        return res.send("blah blah blah");
    }
};

The controller is still accessible at /foo

Share Improve this question edited Nov 14, 2014 at 19:20 t3rminus asked Nov 14, 2014 at 2:21 t3rminust3rminus 1302 silver badges7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

The problem is a little bit tricky. You are trying to open Controller.index method. At the same time you are disabled routing for all actions.

But actually Sails.js in 0.10.5 has additional configuration that disables index route from controller. Its name: index.

So you disabled auto routing for all actions except index..

To disable all auto routes you have to set:

_config: {
    actions: false,
    shortcuts: false,
    rest: false,

    index: false
}

Seems that somebody just forgot to add this into docs.

You can do this by using policies under the config folder.

module.exports.policies = {
    YourControllerName: {
        'find': true,
        '*': false
    }
}

To disable the default rest routes generated for models you should set rest: false in file /config/blueprints.js

This solution is for sails V1.x

  /***************************************************************************
  *                                                                          *
  * Automatically expose RESTful routes for your models?                     *
  *                                                                          *
  ***************************************************************************/

  rest: false,
发布评论

评论列表(0)

  1. 暂无评论