ngrok / ngrok-javascript

Embed ngrok secure ingress into your Node.js apps with a single line of code.
https://ngrok.com
Apache License 2.0
86 stars 17 forks source link

Setting #addr as a string fails #69

Closed sandro-pasquali closed 10 months ago

sandro-pasquali commented 10 months ago

Hi!

Not a bug exactly, but the following code will create the tunnel (on ngrok) yet the forwarding will not work because addr is a String:

const url = await ngrok.connect({
    addr: '3001',
...
});

The tunnel url is created/displayed within ngrok admin, but will just hang in browser (never closes, never gets server response).

Using a Number 3001 works fine.

If I turn on logging I see this:

INFO ngrok_nodejs::tunnel - Tunnel "27b27f0a77201090990099063f1e" TCP forwarding to "3001"

Note that when working correctly the message is ...forwarding to "localhost:3001".

Rather than silently failing maybe a TypeError?

Thanks for the great library...

bobzilladev commented 10 months ago

Hello! Thanks for the feedback, this is an interesting case. When the address is a string, and there is no colon, the value is interpreted as the hostname to connect to. We can change the heuristic to interpret a string that parses to an int as a port, a pull request for that has been merged here: https://github.com/ngrok/ngrok-nodejs/pull/70

Thanks again for raising this issue!