-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-mobile-test-https.sh
More file actions
executable file
·86 lines (73 loc) · 2.61 KB
/
start-mobile-test-https.sh
File metadata and controls
executable file
·86 lines (73 loc) · 2.61 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
#!/bin/bash
# Start Next.js dev server with HTTPS for mobile testing
# Camera requires HTTPS on most browsers
echo "🚀 Starting HTTPS mobile-friendly dev server..."
echo ""
# Check if certificates exist
if [ ! -f "certs/cert.pem" ] || [ ! -f "certs/key.pem" ]; then
echo "❌ SSL certificates not found!"
echo ""
echo "Run ./setup-https.sh first to create certificates"
exit 1
fi
# Get local IP address (Mac/Linux)
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null || echo "IP not found")
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
IP=$(hostname -I | awk '{print $1}')
else
# Windows (using WSL or Git Bash)
IP=$(ipconfig | grep -i "IPv4" | head -1 | awk '{print $NF}')
fi
if [ "$IP" == "IP not found" ]; then
echo "❌ Could not detect IP address. Make sure you're connected to WiFi."
exit 1
fi
echo "📱 Your computer's IP address: $IP"
echo ""
# Backup original .env.local
if [ -f .env.local ]; then
cp .env.local .env.local.backup
echo "💾 Backed up .env.local to .env.local.backup"
fi
# Update NEXTAUTH_URL with HTTPS and network IP
if [ -f .env.local ]; then
sed -i.tmp "s|NEXTAUTH_URL=.*|NEXTAUTH_URL=\"https://$IP:3210\"|g" .env.local
rm .env.local.tmp 2>/dev/null
echo "✏️ Updated NEXTAUTH_URL to https://$IP:3210"
else
echo "⚠️ Warning: .env.local not found"
fi
echo ""
echo "✅ Open this URL on your phone:"
echo ""
echo " https://$IP:3210"
echo ""
echo "⚠️ IMPORTANT: You need to trust the certificate first!"
echo ""
echo "📋 iOS: AirDrop cert.pem to phone → Install → Settings → General → About → Certificate Trust Settings"
echo "📋 Android: Transfer cert.pem → Settings → Security → Install certificate"
echo ""
echo "📌 Make sure your phone is on the same WiFi network!"
echo ""
echo "Press Ctrl+C to stop the server and restore settings"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Cleanup function to restore original .env.local
cleanup() {
echo ""
echo "🛑 Stopping server..."
if [ -f .env.local.backup ]; then
mv .env.local.backup .env.local
echo "✅ Restored original .env.local"
fi
exit 0
}
# Set trap to restore settings on exit
trap cleanup INT TERM
# Start Next.js dev server with HTTPS on all interfaces (port 3210)
npm run dev -- --hostname 0.0.0.0 --experimental-https --experimental-https-key ./certs/key.pem --experimental-https-cert ./certs/cert.pem
# Restore on normal exit
cleanup