Javascript 在所有控制器中添加前缀&;航行服务
嗨,我是node&sails的新手,同时在我的代码中执行一些标准。在sails.js中,我现在有这样一个例子,例如下面Javascript 在所有控制器中添加前缀&;航行服务,javascript,node.js,sails.js,sails-mongo,Javascript,Node.js,Sails.js,Sails Mongo,嗨,我是node&sails的新手,同时在我的代码中执行一些标准。在sails.js中,我现在有这样一个例子,例如下面 api/ controllers/ TestController.js services/ TestServices.js 大多数情况下,我只能使用以下URL格式访问视图: http://localhost/test/ http://localhost/test/<action> 右边的URL应可通过以下方式访问: http://loca
api/
controllers/
TestController.js
services/
TestServices.js
大多数情况下,我只能使用以下URL格式访问视图:
http://localhost/test/
http://localhost/test/<action>
右边的URL应可通过以下方式访问:
http://localhost/prtest/
http://localhost/prtest/<action>
提前谢谢
编辑问题
顺便说一句,我正在为值为以下的控制器使用默认的sails配置:
blueprints: {
actions: true,
rest: true,
shortcuts: true,
prefix: ''
...
}
示例:(my routes.js将如下所示)
如果url具有/test或/test/any_操作,那么路由是否可能分别自动使用controller prTestController或prTestController:any_操作
对于#2,是的,这就是我的意思
多谢
config/routes.js
以进行自定义路由。如果您的控制器名为
PrtestController
,则(如果激活),蓝图将自动为您设置一条路由,以主机/prtest/
。要覆盖此选项,请关闭蓝图,并添加一些自定义路线。如果你在理解帆的魔力方面有困难,我建议你关闭所有的蓝图,或者至少使用不同的设置。通过这样做,您必须手动配置路由和操作。当您了解了蓝图的作用及其原因后,如果您想使用它,请重新启用它 下面是一个更详细地解释蓝图和路线的示例
你好,谢谢你的回复。对于#1,在不改变路线的情况下,有什么解决方案吗?因为我有10个控制器,有10个不同的动作,所以在我的routes.js中,我至少有100个手动路由条目?示例:'/test':'prTestController','/test/index2':'prTestController:index2',…'/test/index9':'prTestController:index9'如果url具有/test或/test/将分别自动使用控制器prTestController或prTestController:,那么路由是否可能?@Nina我不确定。我自己还没有测试过,所以你只能试一下,我想:)我恐怕你必须在关掉蓝图的时候做这些。好的,非常感谢你的时间:)太多了,太痛苦了
http://localhost/test/
http://localhost/test/<action>
'/test': {
controller: 'PrtestController',
action: '<action>'
},
'/test/*': {
controller: 'PrtestController'
}
PrtestController.js > prTestController.js
blueprints: {
actions: true,
rest: true,
shortcuts: true,
prefix: ''
...
'/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'