Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Rails 5.2.1 server listen on all interfaces?

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!

like image 841
aumn26 Avatar asked Oct 12 '18 19:10

aumn26


1 Answers

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'
like image 74
anothermh Avatar answered Nov 05 '22 11:11

anothermh