ngrok
ngrok copied to clipboard
Getting the external URL when starting via foreman
I'm using foreman and a Procfile to start up a bunch of services including ngrok. At it's most simple.
webserver: bundle exec rerun -- rackup -s puma -p 8000
ngrok: sleep 2 && ngrok http --log stdout 8000
Which works just fine. However the only way to get the external URL appears to be to visit http://127.0.0.1:4040/status
Is there any way to print the external URL to the console during startup?
I ran into this myself. The only thought would maybe be to output the log to a file and then add another process to tail that log, something like:
webserver: bundle exec rerun -- rackup -s puma -p 8000
ngrok: sleep 2 && ngrok http --log /tmp/ngrok.log 8000
ngrok-log: touch /tmp/ngrok.log && tail -f /tmp/ngrok.log
That said it doesn't seem to work well.
https://github.com/ddollar/foreman/wiki/Missing-Output suggests that flushing the buffer may help the issue. From what I can see in the go source (and I've never written go), is that adding a flush somewhere around here https://github.com/inconshreveable/ngrok/blob/master/src/ngrok/server/tunnel.go#L91 may resolve it for the tunneling logs. However, maybe a review of all Printf or Sprintf locations would be in order.
This is absolutely filthy but works for me:
web: bundle exec rails server -p 5000
webpacker: bin/webpack-dev-server
ngrok: sleep 2 && ngrok http --log stdout 5000
output: sleep 4 && curl -s 127.0.0.1:4040/status | grep window.common | sed 's/http/\nhttp/g' | grep '^https://' | cut -d'\' -f1 && sleep infinity
Here's a similar version to what @unfunco has above, but uses Ngrok's logging output to find the SSL endpoint and output that, instead of running another process & sleeping.
web: bin/rails server -p $PORT
proxy: ngrok http $PORT --log stdout --log-level info | grep -Eoh "https.+\.ngrok\.io" --line-buffered | awk '{print "Proxy address: " $0; fflush("/dev/stdout")}'
I had to use --line-buffered and fflush here to get the output to show up in Foreman. Not 100% sure how that all works, or how portable this is. You can drop the awk entirely if you're only after the URL, I added some extra text for visibility.
Thank you for opening this issue! As of April 2016, the ngrok service has permanently moved to https://ngrok.com/. To join the community and file bug reports or feature enhancements for the ngrok agent, please go to https://github.com/ngrok/ngrok.
This repository is no longer actively maintained and will be archived soon to reduce confusion with the latest ngrok versions. We thank you for the continued support of ngrok and look forward to seeing you over at ngrok.com and the ngrok Community Repo.