Rails真的很奇怪启动Rails服务器

时间:2016-04-21 05:11:32

标签: ruby-on-rails ruby server

我刚刚使用Rails new启动了一个新的rails应用程序,将默认数据库设置更改为PostgresSQL。我用bin / rails s启动服务器,我觉得这很奇怪

2016-04-21 05:00:33] INFO  WEBrick 1.3.1
[2016-04-21 05:00:33] INFO  ruby 2.1.3 (2014-09-19) [i686-linux]
[2016-04-21 05:00:33] INFO  WEBrick::HTTPServer#start: pid=12160 port=3000


Started GET "/socket.io/?EIO=3&transport=polling&t=LGtCFqz" for 10.0.2.2 at 2016-04-21 05:00:38 +0000

ActionController::RoutingError (No route matches [GET] "/socket.io"):
  actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.6) 

lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.6) lib/rails/engine.rb:514:in `call'
  railties (4.1.6) lib/rails/application.rb:144:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  rack (1.5.5) lib/rack/content_length.rb:14:in `call'
  rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
  /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

堆栈跟踪中的这一行真的让我感到担忧:

Started GET "/socket.io/?EIO=3&transport=polling&t=LGtCFqz" for 10.0.2.2 at 2016-04-21 05:00:38 +0000

我安装了一个名为em-websockets的websocket gem以及thin gem。我从Ruby上卸载了这两个,但我仍然遇到了这个错误。

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# postgres db
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

这是我的宝石文件。据我所知,它与websockets没有任何关系。有没有人对此有任何见解?

谢谢。

2 个答案:

答案 0 :(得分:1)

我在默认rails(0.0.0.0:3000)中重新启动并重新启动了服务器。 它固定了自己。

感谢您的帮助。

答案 1 :(得分:1)

对于那些真的有兴趣知道这里真正发生的事情的人。

这不是Rails应用程序的问题。

默认情况下,Rails在端口http://localhost:3000上运行。

就像Rails App一样,您在端口3000上运行了另一台服务器(例如:Gulp / NodeJS)。现在已关闭与该服务器的连接,并在端口3000上启动了Rails服务器。

现在有趣的部分开始发挥作用。假设旧服务器的客户端之一仍然在端口3000上,但仍在向旧Nodejs服务器发出请求(但在端口3000上却击中Rails)。

因此,实际上客户端正在向NodeJs服务器请求,但是在该端口中,您现在正在运行Rails应用程序。

socket.io是一个实时应用程序,可以与NodeJS很好地配合使用。

这就是为什么您看到这些奇怪的GET请求。

GET "/socket.io/?EIO=3&transport=polling&t=LGtCFqz"

Rails Logger

您所要做的就是确保关闭与Rails应用程序连接的所有浏览器选项卡(连接3000)。