#!/bin/bash

# This script starts both the backend server and the test app

echo "Setting up the SDK for the test app..."
cd test-app
./setup-sdk.sh
cd ..

echo "Starting the backend server..."
# Start the backend server in the background with a different port
PORT=3001 node api/server.js &
BACKEND_PID=$!

echo "Starting the test app server..."
cd test-app
python3 -m http.server 8000 &
TEST_APP_PID=$!

echo ""
echo "Servers started successfully!"
echo "Backend server: http://localhost:3000"
echo "Test app: http://localhost:8000"
echo ""
echo "Press Ctrl+C to stop both servers"

# Function to kill both servers on exit
function cleanup {
  echo ""
  echo "Stopping servers..."
  kill $BACKEND_PID
  kill $TEST_APP_PID
  echo "Servers stopped"
  exit 0
}

# Register the cleanup function for when the script is terminated
trap cleanup SIGINT

# Wait indefinitely
while true; do
  sleep 1
done