robbie-cahill / tunnelmole-client

Tunnelmole - Connect to local servers from anywhere
MIT License
1.22k stars 80 forks source link

Allow the user to get the generated URL #25

Closed gary-archer closed 10 months ago

gary-archer commented 11 months ago

Very nice component - and I like the way you can get multiple generated internet SSL URLs. I was trying to use it for a code example that demonstrated a tricky mobile security use case.

In ngrok you can write the following type of script to spin up a URL and then use the URL value in automation. For example to configure components that use the URLs. A similar feature in your component would also add to its appeal, so thought I'd add a request for that.

ngrok http 80 --log=stdout &
sleep 5
GENERATED_URL=$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[] | select(.proto == "https") | .public_url')

Nothing urgent though - for now I'm writing some script which seems to work alright:

tmole 3000 >mobile_hostnames               &
tmole 3001 >web_hostnames                  &
tmole 8443 >authorization_server_hostnames &
sleep 5

MOBILE_BASE_URL=$(tail -n 1 mobile_hostnames                             | cut -d " " -f1)
WEB_BASE_URL=$(tail -n 1 web_hostnames                                   | cut -d " " -f1)
AUTHORIZATION_SERVER_BASE_URL=$(tail -n 1 authorization_server_hostnames | cut -d " " -f1)
robbie-cahill commented 11 months ago

Nice idea, the best way to do this is to use the npm module and some JavaScript.

npm install --save tunnelmole

Then in your script:

import { tunnelmole } from 'tunnelmole';

const url = await tunnelmole({
    port: 3000
});
// url = https://idsq6j-ip-157-211-195-169.tunnelmole.net

Then just use that URL for the automation.