#!/bin/bash
PORT=8000

if lsof -t -i:$PORT; then
    kill -15 $(lsof -t -i:$PORT)
    sleep 5
fi

python -m pip install uv

if [ ! -d ".venv" ]; then
    uv venv
fi

if [ -z "$VIRTUAL_ENV" ]; then
    source .venv/bin/activate
fi

uv sync

if [ "$ENV" = "dev" ]; then
    exec python -m hypercorn app.main:app --bind 0.0.0.0:$PORT --reload
else
    exec python -m hypercorn app.main:app --bind 0.0.0.0:$PORT
fi