简体   繁体   English

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

[英]Rails really weird issue starting Rails server

I just initiated a new rails app with Rails new, changed the default database settings into PostgresSQL.我刚刚使用 Rails new 启动了一个新的 rails 应用程序,将默认数据库设置更改为 PostgresSQL。 I start the server with bin/rails s and I get this weird我用 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'

This line in the stack trace really concerns me:堆栈跟踪中的这一行确实让我担心:

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

I had a websocket gem installed called em-websockets as well as the thin gem.我安装了一个名为 em-websockets 的 websocket gem 以及瘦 gem。 I uninstalled both from Ruby but I still get this error.我从 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]

This is my gemfile.这是我的 gemfile。 It has nothing with websockets as far as I can tell.据我所知,它与 websockets 无关。 Does anyone have any insight on this?有没有人对此有任何见解?

Thank you.谢谢。

For Anyone who is really interested to know what is really happening here.对于任何真正有兴趣了解这里真正发生的事情的人。

This is not a Rails application issue.这不是 Rails 应用程序问题。

Rails is running on port http://localhost:3000 by default.默认情况下,Rails 在端口 http://localhost:3000 上运行。

Like Rails App, you may have another server (Ex: Gulp / NodeJS ) run on the same port 3000. This server has been stopped and you started Rails server on the port 3000 instead.像 Rails App 一样,你可能有另一个服务器(例如: Gulp / NodeJS )在同一个端口 3000 上运行。这个服务器已经停止,你在端口 3000 上启动了 Rails 服务器。

Now the funny part coming into play.现在有趣的部分开始发挥作用。 One of your old server's client is still requesting to your old Gulp / NodeJS server, assuming that it is still on port 3000 ( but it is hitting Rails on port 3000 :) ).您的旧服务器的一个客户端仍在向您的旧Gulp / NodeJS服务器发出请求,假设它仍在端口 3000 上(但它正在端口 3000 上访问Rails :))。

Actually the client is requesting to Gulp / NodeJS server, in that port you have Rails app running.实际上,客户Gulp / NodeJS在向Gulp / NodeJS服务器发出请求,在该端口中运行 Rails 应用程序。

socket.io is a realtime application that work well with NodeJS. socket.io是一个与 NodeJS 配合良好的实时应用程序。

That is why you see these weird GET requests in your Rails logs.这就是为什么您会在 Rails 日志中看到这些奇怪的GET请求。

GET "/socket.io/?EIO=3&transport=polling&t=LGtCFqz" => this is not supposed to come into Rails application

And you blame Rails application and think why this error is happening !!你责怪 Rails 应用程序并思考为什么会发生这个错误!

Rails 记录器

What you can do is just make sure that all the browser tabs apart from Rails app, that connecting to 3000 is closed.你能做的就是确保除了 Rails 应用程序之外的所有浏览器选项卡都关闭了,连接到 3000。

I rebooted and restarted the server in default rails(0.0.0.0:3000).我在默认 rails(0.0.0.0:3000) 中重新启动并重新启动服务器。 It fixed itself.它自己修好了。

Thanks for all the help.感谢所有的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM