#!/usr/bin/env bash # Development launcher. Pick the service and port: # # ./run.sh # main app on 8000 # ./run.sh main 8000 # main app on 8000 # ./run.sh sensors 8001 # sensors app on 8001 (localhost only) # # The main app calls the sensors API server-to-server. Override its address # when the sensors app is not on localhost:8001: # # SENSORS_API_URL=http://192.168.0.50:9001 ./run.sh main 8000 # # The sensors API is open to every user on the local machine. To expose it # on the network explicitly set HOST=0.0.0.0. set -euo pipefail cd "$(dirname "$0")" APP="${1:-${APP:-main}}" PORT="${2:-${PORT:-}}" case "$APP" in main) MODULE="app:create_app" DEFAULT_PORT=8000 DEFAULT_HOST="0.0.0.0" ;; sensors) MODULE="sensors_app:create_app" DEFAULT_PORT=8001 DEFAULT_HOST="127.0.0.1" ;; *) echo "Usage: $0 [main|sensors] [port]" >&2 exit 2 ;; esac PORT="${PORT:-$DEFAULT_PORT}" HOST="${HOST:-$DEFAULT_HOST}" if [ -x ".venv/bin/python" ]; then PYTHON=".venv/bin/python" else PYTHON="python3" fi echo "Starting $APP app on http://$HOST:$PORT" >&2 exec "$PYTHON" -m flask --app "$MODULE" run --host "$HOST" --port "$PORT" --debug