DEV Community

Steve
Steve

Posted on

Rails 6 and ngrok

Long time lurker, first time caller.

I just recently updated my failed payment application to Rails 6. Went to use Ngrok to test some webhoooks and got an interesting little error. Now, unless you specify a host in rails 6 everything except for localhost gets blocked. Great new security feature. Buuuut, what if I use ngrok regularly and don't have the paid version so I get a new address every time I run it? It's regex to the rescue.

Simply open config/environments/development.rb and then add config.hosts << /[a-z0-9]+\.ngrok\.io/super simple and awesome.

Thought I'd keep it short.

Have an awesome week.

Top comments (10)

Collapse
 
excid3 profile image
Chris Oliver

You can also set config.hosts = nil to disable the feature if you want to let it accept all domains.

Collapse
 
swanny85 profile image
Steve

Ah yeah, didn't think of that.

Collapse
 
excid3 profile image
Chris Oliver

Safer to do it your way. 😜

Thread Thread
 
swanny85 profile image
Steve

Haha, yeah.

Collapse
 
branliang profile image
bran

Thanks for the tip, but this regex doesn't cover all cases. I am using the below regex just to catch all possible hosts.

config.hosts << /.+\.ngrok\.io/
Enter fullscreen mode Exit fullscreen mode
Collapse
 
swanny85 profile image
Steve

Yeah, I'm not regexpert so I'm sure there are spots that can be improved.

Collapse
 
ben profile image
Ben Halpern

Thanks for the tip

Collapse
 
swanny85 profile image
Steve

Thanks for the forum to share said tip!

Collapse
 
fareesh profile image
Fareesh Vijayarangam • Edited

If you are on a regional domain e.g. ap.ngrok.io you can change this to

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

Collapse
 
brenodamata profile image
Breno da Mata

Nice :)