【发布时间】:2014-04-22 06:08:38
【问题描述】:
嗨,我是 node 和sails 的新手,同时在我的代码中做一些标准。在sails.js 我目前有这个,例如下面
api/
controllers/
TestController.js
services/
TestServices.js
大多数情况下,我只能使用这种 URL 格式访问视图:
http://localhost/test/
http://localhost/test/<action>
如果我给我的文件名添加一些前缀,它会变成这样:
api/
controllers/
PrtestController.js
services/
PrtestServices.js
正确的 URL 应该可以通过以下方式访问:
http://localhost/prtest/
http://localhost/prtest/<action>
问题:
1) 如果我为所有控制器和服务文件名添加前缀,是否可以通过以下方式访问 url:
http://localhost/test/
http://localhost/test/<action>
不加前缀?
我正在考虑配置 config/routes.js 以通过编辑以下内容来实现此目的:
'/test': {
controller: 'PrtestController',
action: '<action>'
},
'/test/*': {
controller: 'PrtestController'
}
老实说,我还没有尝试过(这只是我对代码进行重大更改之前的一个想法,否则我可能会搞砸)
2) 是否有可能在sails.js 中有这个
PrtestController.js > prTestController.js
提前致谢!
编辑问题
顺便说一句,我正在为具有以下值的控制器使用默认sails配置:
blueprints: {
actions: true,
rest: true,
shortcuts: true,
prefix: ''
...
} 示例:(我的 routes.js 将如下所示)
'/test' : 'prTestController',
'/test/action2' : 'prTestController:action2',
'/test/action3' : 'prTestController:action3',
'/test/action4' : 'prTestController:action4',
'/test/action5' : 'prTestController:action5',
'/test/action6' : 'prTestController:action6',
'/test/action7' : 'prTestController:action7',
'/test/action8' : 'prTestController:action8',
'/test/action9' : 'prTestController:action9'
如果 url 具有 /test 或 /test/any_action 将自动使用控制器 prTestController 或 prTestController:any_action 的路由是否可能?
对于#2,是的,这就是我的意思。
非常感谢!
【问题讨论】:
标签: javascript node.js sails.js sails-mongo