#!/usr/bin/env bash
# Starts the Chordly server in the foreground.
#
#   ./start.sh            → http://0.0.0.0:3000
#   PORT=8080 ./start.sh  → http://0.0.0.0:8080
#
# The web server (Nginx/Caddy/Apache) must proxy to this port — it must never
# serve this folder as static files, or you will get an "Index of /" page
# instead of the app.

set -euo pipefail

cd "$(dirname "$0")"

export NODE_ENV="${NODE_ENV:-production}"
export PORT="${PORT:-3000}"
export HOSTNAME="${HOSTNAME:-0.0.0.0}"

if ! command -v node >/dev/null 2>&1; then
  echo "Node.js 20+ is required but was not found on PATH." >&2
  exit 1
fi

echo "Chordly starting on http://${HOSTNAME}:${PORT}"
exec node server.js
