【问题标题】:Enigmatic GET request from Rails app来自 Rails 应用程序的神秘 GET 请求
【发布时间】:2013-05-14 01:19:36
【问题描述】:

当我为我的 Rails 应用程序运行服务器时,我看到了一件奇怪的事情。这是日志:

Jatins-MacBook-Pro: silverSpoon$ rails s
=> Booting Thin
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop


Started GET "/app/update-progress" for 127.0.0.1 at 2013-05-19 15:04:56 +0530
Connecting to database specified by database.yml

ActionController::RoutingError (No route matches [GET] "/app/update-progress"):
  actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.8) lib/rails/engine.rb:479:in `call'
  railties (3.2.8) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
  thin (1.5.0) lib/thin/connection.rb:81:in `block in pre_process'
  thin (1.5.0) lib/thin/connection.rb:79:in `catch'
  thin (1.5.0) lib/thin/connection.rb:79:in `pre_process'
  thin (1.5.0) lib/thin/connection.rb:54:in `process'
  thin (1.5.0) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.1) lib/eventmachine.rb:187:in `run_machine'
  eventmachine (1.0.1) lib/eventmachine.rb:187:in `run'
  thin (1.5.0) lib/thin/backends/base.rb:63:in `start'
  thin (1.5.0) lib/thin/server.rb:159:in `start'
  rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
  rack (1.4.1) lib/rack/server.rb:265:in `start'
  railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
  railties (3.2.8) lib/rails/commands.rb:50:in `tap'
  railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `require'
  script/rails:6:in `<main>'

Rendered /Users/silverSpoon/.rvm/gems/ruby-1.9.3-p194@fbTracker/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.3ms)

然后,重复发出请求。请指导我找出这种行为的原因以及如何解决这个问题。

rake:routes 的输出为:

bash-3.2$ rake routes
    trackers        /trackers(.:format)                tracker#index
        root        /                                  home#index
       users POST   /users(.:format)                   users#create
   edit_user GET    /users/:id/edit(.:format)          users#edit
        user GET    /users/:id(.:format)               users#show
             PUT    /users/:id(.:format)               users#update
             DELETE /users/:id(.:format)               users#destroy
                    /auth/:provider/callback(.:format) sessions#create
auth_failure        /auth/failure(.:format)            :controller#:action
     signout        /signout(.:format)                 sessions#destroy
                    /online/:id(.:format)              users#function

如果您需要更多信息,请告诉我。

【问题讨论】:

  • 您是否尝试过使用命令rake 进行测试?什么是错误信息?
  • @hendrathings:我不明白你在问什么“尝试使用命令 rake 进行测试”?能否请您详细说明...
  • 您是否尝试过对您的资源管理器使用匿名会话?或从另一台计算机检查?也许有一个扩展程序在执行神秘的请求,甚至是病毒
  • 查看错误:ActionController::RoutingError (No route matches [GET] "/app/update-progress",尝试为您的应用创建单元测试并使用命令rakerake test:.. 进行跟踪,错误表示没有匹配路由
  • 您是否正在使用任何 JavaScript 或可以将 JavaScript 插入资产管道的 gem?我的猜测是,这是一个获取用于更新进度条的百分比数据的 ajax 请求。重复发出请求是因为为了提供及时的反馈,该栏需要至少每秒更新一次左右。

标签: ruby-on-rails debugging ruby-on-rails-3.2 routes


【解决方案1】:

您的应用没有到/app/update_progress 的路由。因此,在您的应用中调用它是以下之一:

  1. 您的应用程序中的 Javascript 代码(您是否会使用 this Bootstrap Progressbar?)

    要测试这是否是问题的根源 - 打开 Chrome 开发者工具并转到 Network panel。现在打开您的应用程序localhost:3000。如果您在此 Network 选项卡中看到对 localhost:3000/app/update_progress 的一致调用,则表示您的应用程序正在从 Javascript 触发这些请求。现在您需要搜索您的代码库以找出该 javascript 代码的位置。它可能在您下载的一些 jquery 扩展中。你可以create a breakpoint in Javascript whenever an Ajax request is made/app/update_progress

  2. chrome/firefox 扩展

    要排除这种情况,请以隐身模式(通常会禁用所有扩展程序)打开 Chrome/Firefox,然后打开您的应用程序。如果您仍然看到对 /app/update_progress 的点击,那么很可能它不是导致问题的扩展。

  3. 你正在使用的一些外部 gem

    如果以上两个都没有实现,请发布您的 Gemfile。

【讨论】:

  • 你成功了。是的,我在玩 Bootstrap 进度条。最肯定的是,这将是这种行为的原因
  • @JatinGanhotra,您能否检查一下这是否有效,如果有任何问题,请告诉我?
【解决方案2】:

我不确定你的问题是什么。

当你启动你的服务器时,它会收到一个请求

http://127.0.0.1:3000/app/update-progress

但是这个请求没有路由(Rails 不知道如何处理那个请求)所以你得到了那个错误。

要处理该请求,请添加一个路由:

match '/app/update-progress/' => 'some#action'

要了解有关请求的更多信息,请检查操作内部的 request 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2017-05-29
    • 2016-11-13
    • 2012-07-05
    • 2019-08-10
    相关资源
    最近更新 更多