Disabling sails.js default routes

I am setting up a basic Sails.js application and I am trying to disable the default routing system in sails.js. The documentation here seems to indicate that it can be disabled in a file /config/blueprints.js

by settingmodule.exports.blueprints = { actions: false };

However, when I do sails lift

, I can still access my default controller in/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
};

      

Also, the problem keeps popping up if I disable the blueprints for each controller:

/**   /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 available in /foo

+3


source to share


2 answers


The problem is a bit tricky. You are trying to open the Controller.index method. At the same time, you turn off routing for all activities.

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

This way you have disabled automatic routing for all activities except the index.



To disable all automatic routes that you have to install:

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

    index: false
}

      

It seems like someone just forgot to add this to the docs.

+7


source


You can do this using policies in the config folder .



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

      

0


source







All Articles