#!/bin/sh
set -eu

export CRAWLER_HOST="${CRAWLER_HOST:-0.0.0.0}"
export CRAWLER_PORT="${CRAWLER_PORT:-8114}"
export DISPLAY="${DISPLAY:-:99}"

if [ "${CRAWLER_USE_XVFB:-true}" = "true" ]; then
  rm -f /tmp/.X99-lock /tmp/.X11-unix/X99
  Xvfb "$DISPLAY" -screen 0 1920x1080x24 -nolisten tcp &
  sleep 1
fi

cd /crawler/app
exec uvicorn server:app --host "$CRAWLER_HOST" --port "$CRAWLER_PORT"
