gpt4 book ai didi

ruby-on-rails - Rails 真的很奇怪启动 Rails 服务器的问题

转载 作者:行者123 更新时间:2023-12-02 17:28:12 27 4
gpt4 key购买 nike

我刚刚用 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]

这是我的 gemfile。据我所知,它与 websockets 无关。有没有人对此有任何见解?

谢谢。

最佳答案

对于任何真正有兴趣了解这里真正发生的事情的人。

这不是 Rails 应用程序问题。

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

与 Rails 应用程序一样,您可能有另一个服务器(例如:Gulp/NodeJS)在同一端口 3000 上运行。该服务器已停止,您在端口 3000 上启动了 Rails 服务器。

现在有趣的部分开始发挥作用。您的旧服务器的一个客户端仍在向您的旧 Gulp/NodeJS 服务器请求,假设它仍在端口 3000 上(但它正在访问端口 3000 上的 Rails :) ).

实际上,客户端正在请求 Gulp/NodeJS 服务器,在该端口中,您正在运行 Rails 应用程序。

socket.io 是一个与 NodeJS 配合良好的实时应用程序。

这就是为什么您会在 Rails 日志中看到这些奇怪的 GET 请求。

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

然后您责怪 Rails 应用程序并思考为什么会发生此错误!!

Rails Logger

你可以做的只是确保除了 Rails 应用程序之外的所有浏览器选项卡都已关闭,连接到 3000。

关于ruby-on-rails - Rails 真的很奇怪启动 Rails 服务器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760174/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com