- Get ngrok https://ngrok.com/download
- Start ngrok
ngrok http 3000
- In a separate terminal, in your rails directory:
- copy
ngrok-host
script above tobin/
directory (drop the.rb
, its just there for gist syntax highlighting. - make the file executable:
chmod +x bin/ngrok-host
- run:
bin/ngrok-host
The script queries the local ngrok instance for available tunnels, grabs the https host name, and starts rails with that hostname configured for url helpers and the like.
Ngrok is a really useful tool for allowing access to a development server over a public URL with TLS encryption. I specifically needed this for testing an Android react-native client against a rails API.
The problem: starting and stopping Ngrok on a free account rotates and I got tired of copy-pasting the ever-changing hostnames into my rails config when I needed to restart.