Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgraded Rails to 6, getting Blocked host Error

I needed the new function in ActiveStorage to resize_to_fill so I upgraded to Ruby 2.5.1 and Rails 6.

ruby '2.5.1'

gem "rails", github: "rails/rails"

When I stopped, then restarted my server (Cloud 9), I received the below Rails error:

Blocked host: xxxxxxx-xxxxxxx.c9users.io
To allow requests to xxxxxxx-xxxxxxx.c9users.io, add the following configuration:

Rails.application.config.hosts << "xxxxxxx-xxxxxxx.c9users.io"

I've tried restarting, new windows, but nothing worked. I've never seen this error before. I'm guessing the new version of Rails is doing something?

like image 639
Tony S. Avatar asked Dec 21 '18 02:12

Tony S.


3 Answers

The Blocked Host is a new feature of Rails 6. You can add this pattern to your config/environments/development.rb to have no worries of that in case of dynamic urls

config.hosts << /[a-z0-9]+\.c9users\.io/

Also for ngrok user, just replace above c9users by ngrok

Update: ngrok is currently using - and . as subdomain in their URLs so this should be accurate config.hosts << /[a-z0-9-.]+\.ngrok\.io/

Source: https://github.com/MikeRogers0/puma-ngrok-tunnel

like image 90
Dat Le Tien Avatar answered Nov 08 '22 19:11

Dat Le Tien


If you want to disable this functionality on your development environment, you can add config.hosts.clear to config/environments/development.rb.

like image 24
kobaltz Avatar answered Nov 08 '22 18:11

kobaltz


Add this line to config/environments/development.rb

config.hosts << /.*\.ngrok\.io/

Restart your rails server and it will work

like image 28
stevec Avatar answered Nov 08 '22 18:11

stevec