#!/bin/bash
set -e

# Function to check if the database is healthy
check_database() {
  until nc -z -w 1 "$DB_HOST" "$DB_PORT"; do
    >&2 echo "[JET] Waiting for MySQL to be ready..."
    sleep 1
  done
  >&2 echo "[JET] MySQL is ready"
}

# Check if the database is healthy
check_database

# Start the Express app
exec bun run start