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

# Local macOS/Linux launcher for eVentSystem.
#
# Start PHP's built-in server directly so the process receiving HTTP uploads
# uses the large-file limits required by presentation media.
PROJECT_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROUTER="$PROJECT_ROOT/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php"

if [ ! -f "$ROUTER" ]; then
  echo "eVentSystem dependencies are missing. Run: composer install"
  exit 1
fi

UPLOAD_LIMIT="$(php -d upload_max_filesize=256M -r 'echo ini_get("upload_max_filesize");')"
POST_LIMIT="$(php -d post_max_size=1024M -r 'echo ini_get("post_max_size");')"

echo "eVentSystem starting at http://127.0.0.1:8004"
echo "PHP upload limit: $UPLOAD_LIMIT per request file | POST limit: $POST_LIMIT"
echo "eVentSystem application limit: 250 MB per presentation asset"

cd "$PROJECT_ROOT/public"
exec php \
  -d upload_max_filesize=256M \
  -d post_max_size=1024M \
  -d memory_limit=512M \
  -d max_execution_time=600 \
  -d max_input_time=600 \
  -S 127.0.0.1:8004 \
  "$ROUTER"
