Hi all,
Today, we are going to discuss how you can publicly access the local running server with a domain and Cloudflare tunnel.
Pre-requisites
- Domain
- DNS on Cloudflare
- Cloudflare One account access
- Local server
Set up the environment
Application
Make sure your application runs locally on a port like 8000,9000 etc.
Cloudflare Tunnel
- Log in to your Cloudflare One account.
- Go to "Zero Trust".
- Expand Networks and select Connectors.
- Click on “Create a tunnel”.
- Select “Cloudflared”.
- Give a name to your tunnel.
- Click on “Save”.
- In the "Choose your environment" section, select the environment where the server is running.
- Follow the instructions to install and run a connector.
- Here, you need to move to your server machine.
- Open the terminal and perform the instructions to install the "cloudflared" tool.
- Run using the token (part of the command).
- Once the installation is completed. Click on Save.
Add IP/CIDR
- Edit the tunnel to add the IP/CIDR.
- Choose based on your local DHCP.
Published application routes
- Click on “Add a published application route”.
- Give an optional subdomain.
- Select the domain from the dropdown.
- You need to have your domain managed by Cloudflare (DNS).
- An optional path to make sure you have a frontend and a backend that work together.
- Under service, select Type as HTTP, and your local machine server port.
- Select the URL of the server application, including the localport.
- localhost:9000
- Click on “Save”.
In my scenario, the frontend path is * with localhost:9001, and the backend path is api/* with localhost:8000.
Troubleshooted issue
If the frontend with path "/*" is above the backend route, then your backend APIs will never be reached.
So, "move up" the backend with "/api/*" path above the frontend to serve the requests.
Feel free to reach out to me if you have any doubts and clarifications needed at my email psrdotcom@gmail.com
No comments:
Post a Comment