#!/bin/bash
#
# Simple FastAPI Server Startup Script
# 
# This script just starts the FastAPI backend server on churro
# Referenced in supervisord-watchers.conf
#

set -e

# Configuration
APP_DIR="/sphere/app"
VENV_PATH="/sphere/.venv" 
API_HOST="0.0.0.0"
API_PORT="8000"

echo "🚀 Starting Featrix Sphere FastAPI Server..."

# Change to app directory
cd "$APP_DIR"

# Activate virtual environment if it exists
if [ -f "$VENV_PATH/bin/activate" ]; then
    echo "Activating virtual environment..."
    source "$VENV_PATH/bin/activate"
else
    echo "Warning: Virtual environment not found at $VENV_PATH"
fi

# Start the FastAPI server
echo "Starting FastAPI server on $API_HOST:$API_PORT..."
echo "App directory: $APP_DIR"
echo "Python path: $(which python)"

# Use uvicorn with the factory pattern as defined in supervisord config
# Suppress uvicorn access logs - we have custom logging middleware in api.py
exec uvicorn --factory api:create_app --host="$API_HOST" --port="$API_PORT" --reload --no-access-log --log-level info 