Skip to content

Commit c040001

Browse files
richardthe3rdclaude
andcommitted
Add Cloudflare Tunnel support for development
- Add tunnel.cambeerfestival.app to worker CORS allowed origins - Add *.trycloudflare.com wildcard support for quick tunnels - Create dev and dev-tunnel tasks in mise.dev.toml - Add tunnel-setup task for one-time tunnel configuration - Add .cloudflared/config.yml for tunnel configuration - Update .gitignore to exclude tunnel credentials 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f93ca6f commit c040001

5 files changed

Lines changed: 105 additions & 3 deletions

File tree

.cloudflared/config.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloudflare Tunnel Configuration
2+
# This configures a named tunnel for development access via tunnel.cambeerfestival.app
3+
#
4+
# Setup instructions:
5+
# 1. Login to Cloudflare: cloudflared tunnel login
6+
# 2. Create the tunnel: cloudflared tunnel create cbf-dev-tunnel
7+
# 3. Route DNS: cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app
8+
# 4. Run the tunnel: cloudflared tunnel run cbf-dev-tunnel
9+
#
10+
# The tunnel UUID and credentials will be stored in ~/.cloudflared/ after creation
11+
12+
tunnel: cbf-dev-tunnel
13+
credentials-file: /home/vscode/.cloudflared/be8d5634-735e-4637-b030-6f818e739b77.json
14+
15+
ingress:
16+
- hostname: tunnel.cambeerfestival.app
17+
service: http://localhost:8080
18+
- service: http_status:404

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
mise.local.toml
1313
mise.*.local.toml
1414

15+
# Cloudflare Tunnel
16+
.cloudflared/*.json
17+
.cloudflared/cert.pem
18+
1519
# Flutter repo-specific
1620
/bin/cache/
1721
/bin/internal/bootstrap.bat

cloudflare-worker/worker.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const ALLOWED_ORIGINS = [
2323
'https://richardthe3rd.github.io',
2424
'https://cambeerfestival.app',
2525
'https://staging.cambeerfestival.app',
26+
'https://tunnel.cambeerfestival.app',
2627
'http://localhost:8080',
2728
'http://localhost:3000',
2829
'http://127.0.0.1:8080',
@@ -236,6 +237,17 @@ function getCorsHeaders(request) {
236237
};
237238
}
238239

240+
// Allow Cloudflare Tunnel quick tunnels (*.trycloudflare.com)
241+
// Used for local development with cloudflared tunnel
242+
// Security note: These are temporary development tunnels controlled by Cloudflare.
243+
// Only enable this in development/staging workers, not production.
244+
if (origin.endsWith('.trycloudflare.com')) {
245+
return {
246+
'Access-Control-Allow-Origin': origin,
247+
'Access-Control-Allow-Credentials': 'true',
248+
};
249+
}
250+
239251
// Reject all other origins by not including CORS headers
240252
return {};
241253
}

mise.dev.toml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,75 @@ url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d
1818
[macos-x64]
1919
url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/{version}/darwin-x64/claude"
2020
""", version_list_url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/stable" }
21+
cloudflared = "latest"
2122
"npm:firebase-tools" = "14.26.0" # Pin to a stable version for reproducibility
23+
24+
[tasks.dev]
25+
run = '''
26+
echo "Starting Flutter dev server on http://localhost:8080"
27+
flutter run -d web-server --web-port 8080
28+
'''
29+
30+
[tasks.tunnel-setup]
31+
run = '''
32+
echo "Setting up Cloudflare Tunnel for tunnel.cambeerfestival.app"
33+
echo ""
34+
35+
# Check if already logged in
36+
if [ ! -f ~/.cloudflared/cert.pem ]; then
37+
echo "Step 1: Login to Cloudflare (browser will open)..."
38+
cloudflared tunnel login
39+
else
40+
echo "✓ Already logged in to Cloudflare"
41+
fi
42+
43+
# Check if tunnel already exists
44+
if cloudflared tunnel list 2>/dev/null | grep -q "cbf-dev-tunnel"; then
45+
echo "✓ Tunnel 'cbf-dev-tunnel' already exists"
46+
else
47+
echo ""
48+
echo "Step 2: Creating tunnel 'cbf-dev-tunnel'..."
49+
cloudflared tunnel create cbf-dev-tunnel
50+
fi
51+
52+
# Route DNS
53+
echo ""
54+
echo "Step 3: Setting up DNS route for tunnel.cambeerfestival.app..."
55+
cloudflared tunnel route dns cbf-dev-tunnel tunnel.cambeerfestival.app
56+
57+
echo ""
58+
echo "✅ Setup complete! You can now run: MISE_ENV=dev ./bin/mise run dev-tunnel"
59+
'''
60+
61+
[tasks.dev-tunnel]
62+
run = '''
63+
# Start Cloudflare Tunnel in the background
64+
echo "Starting Cloudflare Tunnel..."
65+
cloudflared tunnel --config .cloudflared/config.yml run &
66+
TUNNEL_PID=$!
67+
68+
# Wait for tunnel to be ready
69+
echo "Waiting for tunnel to start..."
70+
sleep 3
71+
72+
echo ""
73+
echo "✅ Tunnel running at: https://tunnel.cambeerfestival.app"
74+
echo ""
75+
echo "Starting Flutter dev server on http://localhost:8080"
76+
echo "Press Ctrl+C to stop both services."
77+
echo ""
78+
79+
# Cleanup function
80+
cleanup() {
81+
echo ""
82+
echo "Stopping tunnel..."
83+
kill $TUNNEL_PID 2>/dev/null
84+
exit
85+
}
86+
87+
# Set up cleanup on exit
88+
trap cleanup EXIT INT TERM
89+
90+
# Run Flutter in foreground (so you can use 'r' for hot reload, etc.)
91+
flutter run -d web-server --web-port 8080
92+
'''

mise.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ echo "To view HTML report, install lcov and run: genhtml coverage/lcov.info -o c
1818

1919
[tasks.analyze]
2020
run = 'flutter analyze --no-fatal-infos'
21-
22-
[tasks.dev]
23-
run = 'flutter run -d web-server --web-port 8080'

0 commit comments

Comments
 (0)