node.js - sails 中的一个策略中的多个 Controller

标签 node.js sails.js

在文档中,我看到我们可以为单个 Controller 定义多个策略,但是是否可以在数组中定义多个 Controller 来使用一个策略?

示例:

['ControllerOne', 'ControllerTwo'] : 'isAuthenticated'

谢谢

最佳答案

不,策略是基于每个 Controller 定义的。但是,您也可以定义通配符策略,因此如果您发现大多数 Controller 都使用某个策略,您可以在通配符中定义该策略,然后处理不需要它的 Controller 分别:

module.exports = {

    // Most controllers use "isAuthenticated" policy...
    '*': 'isAuthenticated',

    // But not PublicController, which is open to everyone...
    'PublicController': {
        '*': true
    },

    // And not StaticController, except for the "uploads" method.
    'StaticController': {
        '*': true,
        'uploads': 'isAuthenticated'
    }

}

关于node.js - sails 中的一个策略中的多个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22495928/

相关文章:

javascript - 在 Express 3 中跨 Jade 模板 block 传递变量

node.js - 在 treeline.io 中使用自定义 Machinepack

javascript - 继承 Sails.js 模型的属性和生命周期函数

node.js - sails 水线自动增量

console - 在其他端口上运行 sails 控制台,然后 sails 抬起

javascript - Socket.io 响应 : How to get server to respond to multiple clients upon receiving info from all clients?

mysql - Node sql语法错误

html - 头部带有脚本的 Nodejs EJS 部分

postgresql - 在 Sails.js 中处理具有数字数据类型的数据库列的最佳方法是什么?

node.js - NodeJS - Promise 在 redis 池等待中返回 undefined object