Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngrok retrieve assigned subdomain

Tags:

node.js

ngrok

I've got a NodeJS script which spins up a ngrok instance, which starts the ngrok binary.

However I'm needing to be able to return back the automatically generated url. I can't find anywhere in the documentation about how to do this.

for example, when you run ngrok http 80 it spins up, generates you a random unique url each time it starts

enter image description here

like image 538
owenmelbz Avatar asked Sep 13 '16 13:09

owenmelbz


2 Answers

This question is kinda old, however, I thought to give another more generic option as it doesn't require NodeJS

curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"https:..([^"]*).*/\1/p'

This one just inspects the response of calling api/tunnels by applying text processing (sed) to the resulted text and identifies the public URL.

like image 141
NikoKyriakid Avatar answered Oct 13 '22 01:10

NikoKyriakid


ngrok serves tunnel information at /api/tunnels. So you can get it like so:

json=$(curl -s http://127.0.0.1:4040/api/tunnels);
node -pe "var data = $json; data.tunnels[0].public_uri"

=> https://719c933a.ap.ngrok.io
like image 35
mroach Avatar answered Oct 12 '22 23:10

mroach