-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-https.sh
More file actions
108 lines (89 loc) · 3.12 KB
/
Copy pathsetup-https.sh
File metadata and controls
108 lines (89 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# HTTPS Setup Script for WebRTC Demo
echo "🔒 Setting up HTTPS for camera access..."
# Option 1: Self-signed certificate (for testing)
setup_self_signed() {
echo "Creating self-signed certificate..."
# Create certificates directory
mkdir -p certs
# Generate private key
openssl genrsa -out certs/key.pem 2048
# Generate certificate
openssl req -new -x509 -key certs/key.pem -out certs/cert.pem -days 365 \
-subj "/C=US/ST=CA/L=SF/O=WebRTC Demo/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1,IP:$(hostname -I | awk '{print $1}')"
echo "✅ Self-signed certificate created in ./certs/"
echo "⚠️ You'll need to accept the security warning in your browser"
}
# Option 2: ngrok tunnel (recommended for phone testing)
setup_ngrok() {
if ! command -v ngrok &> /dev/null; then
echo "❌ ngrok not found. Please install ngrok:"
echo " 1. Visit https://ngrok.com/"
echo " 2. Download and install ngrok"
echo " 3. Run: ngrok authtoken YOUR_TOKEN"
return 1
fi
echo "🌐 Starting ngrok tunnel..."
echo "📱 This will give you an HTTPS URL for your phone"
# Start ngrok in background
nohup ngrok http 3000 > ngrok.log 2>&1 &
sleep 3
# Get the public URL
NGROK_URL=$(curl -s localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
if [ "$NGROK_URL" != "null" ] && [ -n "$NGROK_URL" ]; then
echo "✅ ngrok tunnel active!"
echo "🔗 HTTPS URL: $NGROK_URL"
echo "📱 Use this URL on your phone: $NGROK_URL/phone.html"
echo ""
echo "💡 To stop ngrok: pkill ngrok"
else
echo "❌ Failed to start ngrok tunnel"
echo "Check ngrok.log for details"
fi
}
# Option 3: mkcert (best for development)
setup_mkcert() {
if ! command -v mkcert &> /dev/null; then
echo "❌ mkcert not found. Install with:"
echo " Linux: apt install mkcert"
echo " Mac: brew install mkcert"
echo " Windows: choco install mkcert"
return 1
fi
echo "🔑 Setting up mkcert..."
# Install CA
mkcert -install
# Create certificates
mkdir -p certs
LOCAL_IP=$(hostname -I | awk '{print $1}')
mkcert -key-file certs/key.pem -cert-file certs/cert.pem localhost 127.0.0.1 $LOCAL_IP
echo "✅ mkcert certificate created!"
echo "📱 Your phone will trust this certificate automatically"
}
echo "Choose HTTPS setup method:"
echo "1) ngrok tunnel (recommended for phone testing)"
echo "2) Self-signed certificate (requires accepting browser warning)"
echo "3) mkcert (best for development, requires installation)"
echo ""
read -p "Enter choice [1-3]: " choice
case $choice in
1)
setup_ngrok
;;
2)
setup_self_signed
;;
3)
setup_mkcert
;;
*)
echo "❌ Invalid choice"
exit 1
;;
esac
echo ""
echo "📋 Next steps:"
echo "1. Update docker-compose.yml to use HTTPS"
echo "2. Restart containers: docker-compose up --build"
echo "3. Test on phone using HTTPS URL"