How to configure Rails 5.2.1 server listen on all interfaces?

混江龙づ霸主 提交于 2020-04-13 06:59:00

问题


I'm still fairly new to RoR and learning so please bear with me if I have follow-up questions. Our Rails (v 5.0.2) app was configured to listen on all interfaces with this configuration in config/boot.rb:

require 'rails/commands/server'
module Rails
  class Server
    def default_options
      # make rails listen on all interfaces (accept connections from any ip)
      super.merge(Host: '0.0.0.0', Port: 1234)
    end
  end
end

I recently upgraded Rails from 5.0.2 to 5.2.1 and when I run rails s, I get:

/Users/aum/rails_app/config/boot.rb:5:in `require': cannot load such file -- rails/commands/server (LoadError)
    from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
    from bin/rails:8:in `require_relative'
    from bin/rails:8:in `<main>'

So I updated the 'require' to rails/commands/server/server_command and now I get

rails s
/Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:110:in `<module:Command>': uninitialized constant Rails::Command::Base (NameError)
Did you mean?  Base64
  from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:109:in `<module:Rails>'
  from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:11:in `<top (required)>'
  from /Users/aum/rails_app/config/boot.rb:5:in `require'
  from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
  from bin/rails:8:in `require_relative'
  from bin/rails:8:in `<main>'

I'm not sure how/where to specify the host and port in Rails 5.2.1 since the default_options definitions has also changed here: https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server/server_command.rb#L68

NOTE: I can start the server with rails s -b 0.0.0.0 -p 1234 but that is not what I'm trying to do.

Thanks in advance for your help!


回答1:


Assuming you're using puma, which is the default HTTP server for Rails 5, the binding options are defined in config/puma.rb:

bind 'tcp://0.0.0.0:3000'


来源:https://stackoverflow.com/questions/52785783/how-to-configure-rails-5-2-1-server-listen-on-all-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!