Cloudflare Tunnels (selfhosted)
Connect your selfhosted API to the internet with Cloudflare Tunnels.
Your API works! Fantastic. Now let’s get it online so the world can access it.
There are many ways to connect your API to the Internet, but one of the easiest and most secure ways is using Cloudflare Tunnels. This method allows you to expose your local server to the internet without opening any ports on your router. If you’d like to use a hosted method (that doesn’t require you to run a server on your computer), check out TODO.
However, you will need your own domain managed by Cloudflare. Flavortown offers domain grants, so check it out if you need one!
First, go to Cloudflare Zero Trust in your Dashboard.
Navigate to Networks > Connectors.
Then, click Create a Tunnel and select Cloudflared.
There will be a few setup commands available to run for different operating systems.
Cloudflared with Docker
I would highly recommend using Docker if you plan to run more than one tunnel on your computer. But… we’ll need to make a few changes to the setup command.
Note: Not using Docker? Skip this section!
Docker allows us to run things in containers - in this case, Cloudflared. This means we don’t have to install Cloudflared directly on our computer, and we can run multiple tunnels easily. Install for Mac, Windows, or Linux.
The setup command Cloudflare provides for Docker looks something like this:
docker run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token ey...
We want it to run in the background and have access to your computer’s networking to see your app, so let’s add the -d flag after run and the --network="host" flag before cloudflare/cloudflared:latest:
docker run -d --network="host" cloudflare/cloudflared:latest tunnel --no-autoupdate run --token ey...
Run that command in your terminal.
Pulling it together
Now, whether you’re using Docker or not, you should have Cloudflared running on your computer. Configure it from the UI as such:

Add your domain, pick a subdomain you like, and tada! Your API is now live on the internet. Give yourself a round of applause.