From 4c9076af195215943ad6c51fa51f80ea1fbdc973 Mon Sep 17 00:00:00 2001 From: Lukas Pupka-Lipinski Date: Mon, 6 Oct 2025 09:14:11 +0200 Subject: [PATCH] Update server startup to use uvicorn - Added Python and Windows batch startup scripts with proper configuration --- start_server.bat | 63 ++++++++++++++++++++++++++++++++++ start_server.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ web_todo.md | 2 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 start_server.bat create mode 100644 start_server.py diff --git a/start_server.bat b/start_server.bat new file mode 100644 index 0000000..82639fd --- /dev/null +++ b/start_server.bat @@ -0,0 +1,63 @@ +@echo off +:: AniWorld FastAPI Server Startup Script for Windows +:: This script activates the conda environment and starts the FastAPI server + +echo Starting AniWorld FastAPI Server... +echo. + +:: Check if conda is available +where conda >nul 2>nul +if %errorlevel% neq 0 ( + echo Error: Conda is not available in PATH + echo Please install Anaconda/Miniconda or add conda to your PATH + pause + exit /b 1 +) + +:: Activate the AniWorld conda environment +echo Activating AniWorld conda environment... +call conda activate AniWorld +if %errorlevel% neq 0 ( + echo Error: Failed to activate AniWorld environment + echo Please create the environment first: conda create -n AniWorld python=3.11 + pause + exit /b 1 +) + +:: Check if uvicorn is installed +python -c "import uvicorn" 2>nul +if %errorlevel% neq 0 ( + echo Error: uvicorn is not installed + echo Installing FastAPI dependencies... + pip install -r requirements.txt + if %errorlevel% neq 0 ( + echo Error: Failed to install dependencies + pause + exit /b 1 + ) +) + +:: Set default environment variables if not set +if not defined MASTER_PASSWORD ( + echo Warning: MASTER_PASSWORD environment variable is not set + echo You can set it by running: set MASTER_PASSWORD=your_password + echo. +) + +:: Start the FastAPI server +echo Starting FastAPI server on http://127.0.0.1:8000 +echo Press Ctrl+C to stop the server +echo. +echo Available endpoints: +echo - Web Interface: http://127.0.0.1:8000 +echo - API Documentation: http://127.0.0.1:8000/docs +echo - Alternative API Docs: http://127.0.0.1:8000/redoc +echo. + +:: Start the server with development settings +python -m uvicorn src.server.fastapi_app:app --host 127.0.0.1 --port 8000 --reload --log-level info + +:: If we get here, the server has stopped +echo. +echo Server stopped. +pause \ No newline at end of file diff --git a/start_server.py b/start_server.py new file mode 100644 index 0000000..bd6507b --- /dev/null +++ b/start_server.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +""" +AniWorld FastAPI Server Startup Script + +This script provides a convenient way to start the AniWorld FastAPI server +with proper configuration for both development and production environments. +""" + +import os +import sys +import argparse +import uvicorn +from pathlib import Path + +# Add the project root to Python path +project_root = Path(__file__).parent +sys.path.insert(0, str(project_root)) + + +def main(): + """Main entry point for the server startup script.""" + parser = argparse.ArgumentParser(description="Start AniWorld FastAPI Server") + + # Server configuration arguments + parser.add_argument( + "--host", + default="127.0.0.1", + help="Host to bind the server (default: 127.0.0.1)" + ) + parser.add_argument( + "--port", + type=int, + default=8000, + help="Port to bind the server (default: 8000)" + ) + parser.add_argument( + "--reload", + action="store_true", + help="Enable auto-reload for development (default: False)" + ) + parser.add_argument( + "--workers", + type=int, + default=1, + help="Number of worker processes (default: 1)" + ) + parser.add_argument( + "--log-level", + default="info", + choices=["debug", "info", "warning", "error", "critical"], + help="Log level (default: info)" + ) + parser.add_argument( + "--env", + default="development", + choices=["development", "production"], + help="Environment mode (default: development)" + ) + + args = parser.parse_args() + + # Configure uvicorn based on environment + if args.env == "development": + # Development configuration + uvicorn.run( + "src.server.fastapi_app:app", + host=args.host, + port=args.port, + reload=args.reload, + log_level=args.log_level, + access_log=True, + use_colors=True, + ) + else: + # Production configuration + uvicorn.run( + "src.server.fastapi_app:app", + host=args.host, + port=args.port, + workers=args.workers, + log_level=args.log_level, + access_log=True, + server_header=False, + date_header=False, + ) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/web_todo.md b/web_todo.md index bbb1daa..6eeddf1 100644 --- a/web_todo.md +++ b/web_todo.md @@ -154,7 +154,7 @@ This document contains tasks for migrating the web application from Flask to Fas ### Server Configuration -- [ ] Update server startup to use `uvicorn` instead of Flask development server +- [x] Update server startup to use `uvicorn` instead of Flask development server - [ ] Configure production ASGI server (uvicorn, gunicorn with uvicorn workers) - [ ] Update any reverse proxy configuration (nginx, Apache) - [ ] Test application startup and shutdown