node.js - Sails 在 get-parameters 上给出 404 "."

标签 node.js sails.js

我有 SPA sails 应用程序。我的 SPA 应用程序中的所有路线,首先进入欢迎操作 Controller 。

'/*' :{
    controller : 'Web/welcomeController',
    skipAssets : true
}

所有其他路由都使用类似 api 的 ajax 请求。该路由“/*”仅用于第一个渲染页面。所有其他渲染都提供 angularjs。在那里,其中一个路由有带点的 get 参数。

http://localhost:1337/search?lat=40.714545&long=-74.007112

我收到 404 错误。这一切都是由于参数skipAsset,它忽略了带有内容点的url。

我需要 Controller 还跳过 Assets 资源,如图像、js 等。但正确处理带有内容点 /?lat=40.714545&long=-74.007112

的 get 参数的请求

最佳答案

skipAssets 可能应该修复为忽略查询字符串。但与此同时,您可以使用 skipRegex 代替 skipAssets。来自 Sails.js docs on custom routes :

If skipping every URL containing a dot is too permissive, or you need a route's handler to be skipped based on different criteria entirely, you can use skipRegex. This option allows you to specify a regular expression or array of regular expressions to match the request URL against; if any of the matches are successful, the handler is skipped. Note that unlike the syntax for binding a handler with a regular expression, skipRegex expects actual RegExp objects, not strings.

所以类似:

'/*' :{
    controller : 'Web/welcomeController',
    skipRegex : /^[^?]+\./
}

可能就足够了。

关于node.js - Sails 在 get-parameters 上给出 404 ".",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25704336/

相关文章:

node.js - 如何编译 JSX 服务器端

javascript - 如何使用 EJS 模板语言打破循环?

javascript - 未处理的拒绝 SequelizeEagerLoadingError : modalB is not associated to modelA

javascript - 自更新至 0.10.4 以来 sails 升力错误

mysql - 获取从模型到 View 的字段的可能枚举值

jquery - 我的导航菜单有问题。我正在使用 Bootstrap 3、JQuery 2.3.1、Jade、ExpressJS 和 Node.js

node.js - 使用快速中间件从请求 header 中提取路由

node.js - nodejs Lambda函数中的FFMPEG意外行为

node.js - React webapp在PROD环境中不断加载本地主机资源

node.js - 从 Node 服务器随机流式传输 pdf 文件只在浏览器上显示二进制数据