A quick addendum to my previous ngrok post. If you are not using subdomains, it can be useful for your app to know what ngrok’s dynamically generated URL is. The simplest way to do that is to set an environmental variable. I like APP_URL, but you can use whatever.
config/puma.rb after the ngrok tunnel is started. The entire code
1 2 3 4 5 6 7 8 9
(I’m using the HTTPS URL, but you can swap it out for
With that, you can do things like automatically set callback URLs:
There is an alternative to approach, using
request.base_url as in:
This works fine if you are handling a web request in a controller/view, but isn’t available in models/libraries (unless you pass it in).
Finally, the above is needed to handle a hostname that isn’t static. If it is, you can just set: