Ruby on Rails : is IP port 3000 locked out for external access, on Rails 4.2?
Asked Answered
N

3

5

I run 2 versions on my RoR application on my computer: One is for demos (stable state, RoR 4.0), the other one is for development (RoR 4.2). Both versions can be accessed using http://localhost:3000.

But I noticed an annoying difference: The Demo version can be accessed from another computer on the network. The Dev version cannot. This will be a big trouble when the Dev version is stabilized and becomes the Demo. My customer wants to test on his own laptop, through the wlan.

Is there a "firewall" feature newly implemented ? Is it one of my Gems ?

I would be glad if someone can explain to me this changed behaviour !

Server is Webrick WEBrick 1.3.1 for both environments. Here are my gem files:

Development (not accessible from another computer)

source 'https://rubygems.org'
ruby '2.2.0'

gem 'rails', '~> 4.2.0'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'sass-rails',   '~> 5.0.1'
gem 'coffee-rails', '~> 4.1.0'
gem 'uglifier', '~> 2.7'
gem 'bcrypt', '~> 3.1.10'
gem 'jquery-rails', '~> 4.0.3'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '~> 2.2.6'
gem 'bootstrap-datepicker-rails', '~> 1.3.1'
gem 'will_paginate', '~> 3.0.7'
gem 'bootstrap-will_paginate', '~> 0.0.10'
gem 'selenium-webdriver', '~> 2.44.0'
gem 'sequenced', '~> 2.0.0'
gem 'annotate', '~> 2.6.5'
gem 'rspec-rails', '~> 3.2.0'
gem 'capybara', '~> 2.4.4'
gem 'factory_girl_rails', '~> 4.5.0' 

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

# gem for dev and test only
group :development, :test do
  gem 'pg'  
end

# gem for ORACLE POC
group :ORACLE do
  gem 'ruby-oci8', '~> 2.1.7'
 gem 'activerecord-oracle_enhanced-adapter', github: 'rsim/oracle-enhanced', branch: 'rails42'
#  gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.5'
end

# gem for production
group :production do
  gem 'rails_12factor'
  gem 'pg'
end

Demo (can be accessed from external computer)

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '~> 4.0.0'
gem 'bootstrap-sass', '2.3.2'
gem 'sass-rails',   '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '2.1.2'
gem 'bcrypt', '~> 3.1.0'
gem 'jquery-rails', '~> 3.0.4'
gem 'turbolinks', '1.3.0'
gem 'jbuilder', '1.4.2'
gem 'bootstrap-datepicker-rails'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'selenium-webdriver', '2.42.0'
gem 'sequenced'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

# gem for dev and test only
group :development, :test do
  gem 'pg'
  gem 'annotate', '2.5.0'
  gem 'rspec-rails', '2.14.0'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.0'
end
# gem for ORACLE POC
group :ORACLE do
  gem 'ruby-oci8', '~> 2.1.0'
  gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.0'
  gem 'annotate', '2.5.0'
  gem 'rspec-rails', '2.14.0'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.0'
end

# gem for production
group :production do
  gem 'rails_12factor'
  gem 'pg'
end

Thanks for your help !

Fred

Nevsa answered 28/3, 2015 at 14:25 Comment(0)
A
9

It does seem that Rails 4.2 doesn't allow external access from localhost:3000. Why they did this, I cannot tell you. However, one solution that worked for me just a few days ago is to change the IP address your app uses for development. So call this when starting your server:

rails s -b (address) -p 3000 -e development

Replacing (address) with your internal IP address (usually 192.168.1.x).

Ahumada answered 28/3, 2015 at 14:44 Comment(1)
I don't know rails, but on other platfroms binding to localhost binds only to the 127.0.0.1 interface and binding to 0.0.0.0 will bind to all interfaces including the external one. So binding to localhost will make it only accessable local. This is e.g. usefull if you want to make sure that a service is really only available locally.Hallerson
R
10

Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. Refer 4.2 release notes Start your server with :

rails server -b 0.0.0.0

to restore old behaviour

Radioluminescence answered 7/10, 2015 at 5:40 Comment(0)
A
9

It does seem that Rails 4.2 doesn't allow external access from localhost:3000. Why they did this, I cannot tell you. However, one solution that worked for me just a few days ago is to change the IP address your app uses for development. So call this when starting your server:

rails s -b (address) -p 3000 -e development

Replacing (address) with your internal IP address (usually 192.168.1.x).

Ahumada answered 28/3, 2015 at 14:44 Comment(1)
I don't know rails, but on other platfroms binding to localhost binds only to the 127.0.0.1 interface and binding to 0.0.0.0 will bind to all interfaces including the external one. So binding to localhost will make it only accessable local. This is e.g. usefull if you want to make sure that a service is really only available locally.Hallerson
H
2

You can just simply start with rails s -b 192.168.1.13 as our default port and environment it will pick automatically.

Replace your internal IP address.

Hudis answered 23/6, 2015 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.