Host Your Projects via Cloudflared Tunnel
This is a showcase of hosting your services from localhost to internet via Cloudflare tunnel managed locally and the local operating system is macOS.
In my humble opinion Cloudflare Tunnel is the best option out there. It is free, easy to setup and you can use custom domains.
This is a free feature of Cloudflare introduced by https://blog.cloudflare.com/tunnel-for-everyone/. You can find docs by https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/. Docs were sufficent in my case except for running the tunnel as service. I had to add configure daemon agent of macOS.
Set up your tunnel
This chapter is exactly same from Get started to create a locally-managed tunnel of official documentation. https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-local-tunnel/
Create a Cloudflare Account
I am also using Cloudflare DNS services for my custom domains and I suggest this to easily create custom domain to your local services.
Install cloudflared CLI and Create Tunnel
You can use one tunnel to host more than one service from your localhost so this name does not need to be a service specific name
Configure Tunnel in macOS
Run the Tunnel
Run tunnel manually
Run tunnel as a user (not system) service in macOS
Extra steps are required to run service according to config file we created. Even though documentation explicitly states it uses automatically the user config file. However in mycase the installed service only created quick try tunnel.
Edit plist config
<><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.cloudflare.cloudflared</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/cloudflared</string> <string>tunnel</string> <string>run</string> </array> <key>RunAtLoad</key> <true/> <key>StandardOutPath</key> <string>/Users/<user-name>/Library/Logs/com.cloudflare.cloudflared.out.log</string> <key>StandardErrorPath</key> <string>/Users/<user-name>/Library/Logs/com.cloudflare.cloudflared.err.log</string> <key>KeepAlive</key> <dict> <key>SuccessfulExit</key> <false/> </dict> <key>ThrottleInterval</key> <integer>5</integer> </dict> </plist>
Check launchctl service && Boot the com.cloudflare.cloudflared
Check Output and Error files
3.2 Manually Start/Stop the service
Extra Step: Monitoring Services
I have started using Uptime Robot to monitor my services as it is free up to 50 monitors and easy to set up.
Just add the http health url and it is good to go with 5 min. intervals.