DEV Community

Cover image for Share your localhost with Cloudflare tunnels
Sean Boult
Sean Boult

Posted on

Share your localhost with Cloudflare tunnels

From time to time you'll want to share your locally running app with some folks before it's ready to ship.

Features

🤑 Free to use
💎 Not heavily rate limited
🔒 HTTPS support
🌎 Won't expose your IP

First make sure you have cloudflared installed and setup. You can check out the cloudflared docs for setup instructions.

Now we can create our first tunnel by running the following command.

cloudflared tunnel create mycoolapp
Enter fullscreen mode Exit fullscreen mode

Create a custom subdomain entry with ease just by running this command.

cloudflared tunnel route dns mycoolapp demo.boult.me
Enter fullscreen mode Exit fullscreen mode

Once your app is running you can expose it via the tunnel.

cloudflared tunnel --url http://localhost:8080 run mycoolapp
Enter fullscreen mode Exit fullscreen mode

Now you or a friend can visit the subdomain setup in one of the prior steps.

Image description

Discussion (7)

Collapse
steinbring profile image
Joe Steinbring

That's kind of cool. I'm using a dynamic dns service and a handful of open ports right now to do the same basic thing. Cloudflare Tunnel sounds like a sounder (and cheaper) alternative. :)

Collapse
matttunney profile image
Matt Tunney

Very nice. Gonna try this on Monday.

Collapse
maxfindel profile image
Max F. Findel

This is awesome, I use cloudflare a lot and I didn't know this existed!

Collapse
ironcladdev profile image
IroncladDev

Whoah! Thank you so much for this! Now I can share my localhost without fear of my ip being leaked!!

Collapse
moopet profile image
Ben Sinclair

There are a lot of services that do this, like localtunnel for example, which don't require you to do any weird setup involving "zero trust dashboards" or creating "applications".

I'm not sure how the DNS resolution in this is supposed to work - in your example, you're mapping to demo.boult.me but presumably you have to set that with a CNAME to something inside Cloudflare first.

Collapse
hacksore profile image
Sean Boult Author

I agree that there are less complicated solutions like ngrok or localtunnel that can achive the same thing but if you already use cloudflare it's another option to try out.

When you login to cloudflared CLI you select a domain on your account to use. The second command will create the CNAME for you but you can manually configure it AFAIK.

Configure the CNAME manually

CNAME demo.boult.me <uuid>.cfargotunnel.com
Enter fullscreen mode Exit fullscreen mode
Collapse
moopet profile image
Ben Sinclair

Ah, so you need to have a domain managed by Cloudflare already, gotcha.