#!/usr/bin/env bash
# Production entrypoint — validates build artifacts then starts Node
set -euo pipefail
cd "$(dirname "$0")/.."

# Prevent dev DATABASE_PATH leakage from parent shell
unset DATABASE_PATH

if [[ ! -f server/dist/index.js ]]; then
  echo "ERROR: server/dist/index.js missing — run: npm run build" >&2
  exit 1
fi

if [[ ! -f web/dist/index.html ]]; then
  echo "ERROR: web/dist/index.html missing — run: npm run build" >&2
  exit 1
fi

if [[ -f deploy/ticket-gate.env ]]; then
  set -a
  # shellcheck disable=SC1091
  source deploy/ticket-gate.env
  set +a
fi

exec node server/dist/index.js
