eletrotupi / tcc/ frontend/scripts/adb-reverse.shdcee93d0c11ceff985805b7785c7db54c2acc4dd
1.1 KB | 41 lines Raw
1
#!/bin/sh
2
#
3
# Point the device's localhost at this machine, so a development build can
4
# reach Metro and the API without a LAN IP
5
#
6
#   adb reverse tcp:8081 tcp:8081   # Metro
7
#   adb reverse tcp:3000 tcp:3000   # the API
8
#
9
# With this in place `npx expo start --localhost` is accurate, and the app
10
# derives its API base URL as http://localhost:3000 (no LAN IP in .env.local)
11
#
12
# adb tears these tunnels down when the device disconnects, so re-run this
13
# after reconnecting. A wireless-debugging session is enough; no cable needed
14
#
15
# Usage: adb-reverse.sh
16
set -eu
17

18
METRO_PORT=${METRO_PORT:-8081}
19
API_PORT=${API_PORT:-3000}
20

21
command -v adb >/dev/null 2>&1 || {
22
  echo "adb-reverse: adb not found; install android-tools (Linux) or platform-tools" >&2
23
  exit 1
24
}
25

26
if [ "$(adb get-state 2>/dev/null)" != "device" ]; then
27
  adb devices >&2 || true
28
  echo "adb-reverse: no device ready; connect over USB or enable wireless debugging" >&2
29

30
  exit 1
31
fi
32

33
for port in "$METRO_PORT" "$API_PORT"; do
34
  adb reverse "tcp:$port" "tcp:$port"
35
done
36

37
echo "adb-reverse: device localhost now reaches this machine"
38
adb reverse --list
39

40
echo
41
echo "Next: npx expo start --localhost"