Sails.js正则expression式路由

我正在构build一个简单的sails.js项目,并实现与骨干的前端。

理想情况下,我想要一个单一的路线到我的骨干应用程序服务的一个索引页面。

'/*': { view: 'home/index' } 

这很好,所以现在任何URL都会进入主页。 除了现在,到任何资产(.js,.css,.html,.jpg)的所有路线都不能工作了。

我可以在config.routes.js看到这个注释:

 // NOTE: // You'll still want to allow requests through to the static assets, // so we need to set up this route to ignore URLs that have a trailing ".": // (eg your javascript, CSS, and image files) 'get /*(^.*)': 'UserController.profile' 

但对我来说没有任何意义。 如何忽略带有文件扩展名的路由

我也用'api', localhost:1337/api/controller/为我的所有的CRUDurl添加了前缀,所以也需要一个正则expression式来排除这些转发。 我无法find任何信息如何在任何地方做到这一点。

我必须在这里错过一些基本的东西。

谢谢!

您可以使用skipAssets和skipRegex标志。 这将不会踩在你的静态资产,并不会阻止你的api URL以/ api开头。 我在html5Mode中使用了sails.js和angular。

  "get *":{ controller:"PagesController", action:"index", skipAssets: true, skipRegex: /^\/api\/.*$/ } 

我认为这是一个错误,但我find了解决方法。

'get /[^.?]+?': 'UserController.profile'

或者你可以使用其他的。 只有/user/profile将执行UserController.profile 。 静态目录仍然很好。

'get /:action( user | profile)': 'UserController.profile'