#!/bin/bash

# Change to correct values
#USER=root
#PASS=root
##HOST=localhost
DB=tests
# or to use remote db for dev
#export CLEARDB_DATABASE_URL="mysql://${USER}:${PASS}@${HOST}/${DB}?reconnect=true"

# Can override the port through `bin/local.sh 8088`
WEBPORT=${1:-8080}

export ENV='LOCAL'
open http://localhost:$WEBPORT
php -S localhost:$WEBPORT -t webroot webroot/server.php &
SERVER_PID=$!

echo " "
echo " - Backend server runnin on http://localhost:${WEBPORT} with PID: ${SERVER_PID}"
echo " - NPM Watcher running on PID: ${NPM_WATCHER}"
echo " "

function gracefullyExit {
  echo " "
  echo " - Stopping Backend Server"
  kill $SERVER_PID

  echo " - DONE"
  echo " "
  exit 0
}

trap gracefullyExit SIGINT

while true; do
    sleep 1;
done
