#!/usr/bin/env bash
set -e

DIR="$(cd "$(dirname "$0")" && pwd)"
PORT=5001
ENDPOINT=http://localhost:$PORT

# start the dev server in background
vercel dev --listen $PORT > /dev/null 2>&1 &

printf 'server starting ' 1>&2

# ping the localstack /health endpoint until it shows dynamo is running
until (curl --silent ${ENDPOINT}/health | grep "\"status\":\"ok\"" > /dev/null); do
  printf '.' 1>&2
  sleep 1
done

printf "\nserver started ${ENDPOINT}" 1>&2

echo $ENDPOINT
