我有一个Rails API,并在我的application.rb
中设置了Rack::Cors
,以防止来自https://my-website.com
以外的任何来源的请求,如下所示:
config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'https://my-website.com'
resource '*',
headers: %w[Authorization],
methods: %i[get post put delete options head],
expose: %w[Authorization]
end
end
此外,我还允许websocket连接,如下所示:
config.action_cable.url = %r{/wss:\/\/*/}
config.action_cable.allowed_request_origins = 'https://my-website.com'
最后,我有一个用于Application Load Balancer
的status
检查器,为此我允许对/status
的http请求,如下所示:
config.force_ssl = true
config.ssl_options = {
hsts: { subdomains: true },
redirect: { exclude: ->(request) { request.path =~ /status/ } }
}
所以你可以看到,除了/status
之外的每个路径都应该只是https
,但是我仍然在我的产品错误跟踪器中得到如下错误:
#590 ActionController::RoutingError: No route matches [OPTIONS] "/"
在详细信息中,我获得的源代码如下:
当我的CORS configuration
中没有添加原点时,某人如何设法到达我的实际路径
发布于 2019-06-26 22:17:24
Rack::Cors
只响应OPTIONS
请求,如果请求有Access-Control-Request-Method
头,如果有人发出没有它的请求-请求将命中您的常规路由。
还要注意的是,CORS只是浏览器允许跨域请求的一种方法,任何人都可以使用一些非浏览器脚本或工具来伪造他们想要的任何请求。
https://stackoverflow.com/questions/56774365
复制相似问题