ngrok icon indicating copy to clipboard operation
ngrok copied to clipboard

Passing a custom hostname while creating the ngrok instance programatically

Open subhanahmed047 opened this issue 4 years ago • 7 comments

I'm trying to create a ngrok instance with a custom hostname, but It looks like the ngrok options object doesn't accept the hostname, so how do we create an instance that is using our custom domain rather than default ngrok.io?

Here is how I'm doing it:

await ngrok.connect({
    authtoken: TOKEN,
    hostname: 'mydomain.io', // this doesn't exist
    subdomain: uuid,
    region: 'au',
    port,
 });

subhanahmed047 avatar Dec 06 '21 01:12 subhanahmed047

What happens when you try to set up the tunnel like that? Is there an error?

philnash avatar Dec 06 '21 09:12 philnash

can confirm that hostname works for the whitelabel/CNAME option. just leave off subdomain

mquinnv avatar Dec 06 '21 15:12 mquinnv

running the following piece of code:

await ngrok.connect({
        port,
        region,
        authtoken,
        hostname: '*.mydomain.io', // this is registered in ngrok dashboard and CNAME DNS records are also set
      });

I get the following error:

TypeError: Cannot read property 'body' of undefined

I raised the issue because I also noticed that the types for Ngrok.Options object doesn't contain a hostname property either.

subhanahmed047 avatar Dec 06 '21 22:12 subhanahmed047

Thanks @subhanahmed047, I'll take a look.

philnash avatar Dec 06 '21 22:12 philnash

my code that works in webpack devServer onListening is:

server.public = await ngrok.connect({
                       addr: localPort,
                       hostname: process.env.NGROK_DOMAIN,
                       authtoken: process.env.NGROK_AUTHTOKEN,
                   })

where hostname is my exact entry in ngrok of the form host.domain.net. i'm not sure why the local port is called addr, perhaps you can specify the interface as well as the port

mquinnv avatar Dec 07 '21 14:12 mquinnv

@subhanahmed047 Can you check if it works with a fully qualified hostname?

philnash avatar Dec 13 '21 11:12 philnash