loading...

Rails 6 and ngrok

swanny85 profile image Steve ・1 min read

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.

Discussion

pic
Editor guide
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 Author

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 Author

Haha, yeah.

Collapse
fareesh profile image
Fareesh Vijayarangam

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
ben profile image
Ben Halpern

Thanks for the tip

Collapse
swanny85 profile image
Steve Author

Thanks for the forum to share said tip!

Collapse
brenodamata profile image