eletrotupi / tcc/ commit / 3889890

frontend: add an adb reverse helper for the dev loop

Pointing the device's localhost at the development machine removes the
need to retype the Metro URL whenever the machine's IP changes, and
makes the printed QR/URL accurate. The helper forwards Metro and the API
ports; it has to be re-run per adb session because the tunnels are
dropped on disconnect
Pedro Lucas Porcellis porcellis@eletrotupi.com · 13 days ago 3889890d76a27e3bf87944b2dd355476c36bb4cf Browse files
Parents 37df513
Changed files
2
Additions
+42
Deletions
0
frontend/package.json
1 1
{
2 2
  "name": "orbit",
3 3
  "main": "expo-router/entry",
4 4
  "version": "0.0.0",
5 5
  "scripts": {
6 6
    "start": "expo start",
7 7
    "reset-project": "node ./scripts/reset-project.js",
8 8
    "android": "expo run:android",
9 +
    "android:reverse": "sh scripts/adb-reverse.sh",
9 10
    "lint": "expo lint",
10 11
    "ios": "expo run:ios",
11 12
    "test:e2e": "sh scripts/e2e.sh test",
12 13
    "test:e2e:env": "sh scripts/e2e.sh print-env"
13 14
  },
64 65
    "eslint-config-expo": "~57.0.2",
65 66
    "typescript": "~6.0.3"
66 67
  },
67 68
  "private": true
68 69
}
/dev/null → frontend/scripts/adb-reverse.sh
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"