【问题标题】:How can I route unmatched OPTION requests in Rails 5如何在 Rails 5 中路由不匹配的 OPTION 请求
【发布时间】:2018-05-04 23:50:07
【问题描述】:

我的服务器受到对我的根路径的零星 OPTIONS 请求的攻击。这些都是试图寻找漏洞的机器人。我想返回 404 not found 而不是引发错误,因为我的错误跟踪服务一直都在受到攻击。

我尝试过使用:

options '/', to: 'application#return_not_found'

正确路由这些请求,但是 Rails 5 给了我一个错误。

【问题讨论】:

  • Rails 给出了什么错误?
  • 错误是:undefined method 'options' for #<ActionDispatch::Routing::Mapper:0x007f8ee2b57a20> (NoMethodError)

标签: ruby-on-rails


【解决方案1】:

根据this answer,可以使用:

match '/' => 'application#return_not_found', via: :options

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    相关资源
    最近更新 更多