-
Notifications
You must be signed in to change notification settings - Fork 3
Add Cloudflare Tunnel support for development #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||
| # Cloudflare Tunnel Configuration | ||||||||||||
| # This configures a named tunnel for development access via tunnel.cambeerfestival.app | ||||||||||||
| # | ||||||||||||
| # Setup instructions: | ||||||||||||
| # 1. Login to Cloudflare: cloudflared tunnel login | ||||||||||||
| # 2. Create the tunnel: cloudflared tunnel create cbf-dev-tunnel | ||||||||||||
| # 3. Route DNS: cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app | ||||||||||||
| # 4. Run the tunnel: cloudflared tunnel run cbf-dev-tunnel | ||||||||||||
| # | ||||||||||||
| # The tunnel UUID and credentials will be stored in ~/.cloudflared/ after creation | ||||||||||||
|
|
||||||||||||
| tunnel: cbf-dev-tunnel | ||||||||||||
| credentials-file: /home/vscode/.cloudflared/be8d5634-735e-4637-b030-6f818e739b77.json | ||||||||||||
|
Comment on lines
+11
to
+13
|
||||||||||||
| tunnel: cbf-dev-tunnel | |
| credentials-file: /home/vscode/.cloudflared/be8d5634-735e-4637-b030-6f818e739b77.json | |
| # The credentials file is auto-resolved by cloudflared; do not hardcode the path. | |
| tunnel: cbf-dev-tunnel |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ const ALLOWED_ORIGINS = [ | |||||||||||||||||||||
| 'https://richardthe3rd.github.io', | ||||||||||||||||||||||
| 'https://cambeerfestival.app', | ||||||||||||||||||||||
| 'https://staging.cambeerfestival.app', | ||||||||||||||||||||||
| 'https://tunnel.cambeerfestival.app', | ||||||||||||||||||||||
| 'http://localhost:8080', | ||||||||||||||||||||||
| 'http://localhost:3000', | ||||||||||||||||||||||
| 'http://127.0.0.1:8080', | ||||||||||||||||||||||
|
|
@@ -236,6 +237,17 @@ function getCorsHeaders(request) { | |||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Allow Cloudflare Tunnel quick tunnels (*.trycloudflare.com) | ||||||||||||||||||||||
| // Used for local development with cloudflared tunnel | ||||||||||||||||||||||
| // Security note: These are temporary development tunnels controlled by Cloudflare. | ||||||||||||||||||||||
| // Only enable this in development/staging workers, not production. | ||||||||||||||||||||||
| if (origin.endsWith('.trycloudflare.com')) { | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| 'Access-Control-Allow-Origin': origin, | ||||||||||||||||||||||
| 'Access-Control-Allow-Credentials': 'true', | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+240
to
+250
|
||||||||||||||||||||||
| // Allow Cloudflare Tunnel quick tunnels (*.trycloudflare.com) | |
| // Used for local development with cloudflared tunnel | |
| // Security note: These are temporary development tunnels controlled by Cloudflare. | |
| // Only enable this in development/staging workers, not production. | |
| if (origin.endsWith('.trycloudflare.com')) { | |
| return { | |
| 'Access-Control-Allow-Origin': origin, | |
| 'Access-Control-Allow-Credentials': 'true', | |
| }; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,4 +18,75 @@ url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d | |||||||||||||||||||||||
| [macos-x64] | ||||||||||||||||||||||||
| url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/{version}/darwin-x64/claude" | ||||||||||||||||||||||||
| """, version_list_url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/stable" } | ||||||||||||||||||||||||
| cloudflared = "latest" | ||||||||||||||||||||||||
| "npm:firebase-tools" = "14.26.0" # Pin to a stable version for reproducibility | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [tasks.dev] | ||||||||||||||||||||||||
| run = ''' | ||||||||||||||||||||||||
| echo "Starting Flutter dev server on http://localhost:8080" | ||||||||||||||||||||||||
| flutter run -d web-server --web-port 8080 | ||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [tasks.tunnel-setup] | ||||||||||||||||||||||||
| run = ''' | ||||||||||||||||||||||||
| echo "Setting up Cloudflare Tunnel for tunnel.cambeerfestival.app" | ||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Check if already logged in | ||||||||||||||||||||||||
| if [ ! -f ~/.cloudflared/cert.pem ]; then | ||||||||||||||||||||||||
| echo "Step 1: Login to Cloudflare (browser will open)..." | ||||||||||||||||||||||||
| cloudflared tunnel login | ||||||||||||||||||||||||
| else | ||||||||||||||||||||||||
| echo "✓ Already logged in to Cloudflare" | ||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Check if tunnel already exists | ||||||||||||||||||||||||
| if cloudflared tunnel list 2>/dev/null | grep -q "cbf-dev-tunnel"; then | ||||||||||||||||||||||||
| echo "✓ Tunnel 'cbf-dev-tunnel' already exists" | ||||||||||||||||||||||||
| else | ||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||
| echo "Step 2: Creating tunnel 'cbf-dev-tunnel'..." | ||||||||||||||||||||||||
| cloudflared tunnel create cbf-dev-tunnel | ||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Route DNS | ||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||
| echo "Step 3: Setting up DNS route for tunnel.cambeerfestival.app..." | ||||||||||||||||||||||||
| cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app | ||||||||||||||||||||||||
|
Comment on lines
+53
to
+55
|
||||||||||||||||||||||||
| echo "" | |
| echo "Step 3: Setting up DNS route for tunnel.cambeerfestival.app..." | |
| cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app | |
| # Check if DNS route already exists | |
| if cloudflared tunnel route list 2>/dev/null | grep -q "tunnel.cambeerfestival.app"; then | |
| echo "✓ DNS route for tunnel.cambeerfestival.app already exists" | |
| else | |
| echo "" | |
| echo "Step 3: Setting up DNS route for tunnel.cambeerfestival.app..." | |
| cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app | |
| fi |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dev-tunnel task uses kill $TUNNEL_PID 2>/dev/null which may not properly clean up the cloudflared process if it has spawned child processes. Consider using kill -- -$TUNNEL_PID to kill the entire process group, or use a more robust cleanup mechanism.
Additionally, the 3-second sleep is arbitrary and may not be sufficient for the tunnel to fully start, especially on slower systems. Consider adding a retry loop that checks if the tunnel is actually responding:
# Wait for tunnel to be ready
echo "Waiting for tunnel to start..."
max_attempts=10
attempt=0
while ! curl -s -o /dev/null -w "%{http_code}" https://tunnel.cambeerfestival.app/health | grep -q "200"; do
attempt=$((attempt + 1))
if [ $attempt -ge $max_attempts ]; then
echo "Tunnel failed to start after ${max_attempts} seconds"
kill $TUNNEL_PID 2>/dev/null
exit 1
fi
sleep 1
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The setup instructions in the comments reference manual
cloudflaredcommands, but developers are expected to use thetunnel-setupmise task instead. The comments should be updated to reference the mise task for consistency: