#!/usr/bin/env bash
# Run ON the VPS. Curls the staging service's key routes on 127.0.0.1:8090 and exits non-zero
# on any failure. Does not touch the live tunnel (8085) or the public site at all.
set -uo pipefail

BASE="http://127.0.0.1:8090"
FAIL=0

check() {
  local path="$1" want="$2"
  local code
  code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 "$BASE$path")
  if [ "$code" = "$want" ]; then
    echo "OK   $path -> $code"
  else
    echo "FAIL $path -> $code (wanted $want)"
    FAIL=1
  fi
}

check "/" 200
check "/j/9999" 200
check "/static/app.css" 200
check "/on/9999" 200
check "/take5/9999" 200

if [ "$FAIL" = "1" ]; then
  echo "SMOKE FAILED"
  exit 1
fi
echo "SMOKE OK"
