Spaces:
Sleeping
Sleeping
File size: 1,810 Bytes
5be081e 665a2ea 5be081e 665a2ea 5be081e 665a2ea 5be081e 665a2ea 5be081e 665a2ea 5be081e 665a2ea 5be081e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #!/usr/bin/env python3
"""
Development Server Startup Script for Todo API
This script starts the FastAPI development server with hot-reload enabled.
Usage:
python run_dev.py
Configuration:
- Reads from backend/.env file
- Default port: 8000
- Default host: 0.0.0.0 (accessible from network)
Requirements:
- BETTER_AUTH_SECRET must be set in .env
- DATABASE_URL must be set in .env
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Verify required environment variables
required_vars = ["BETTER_AUTH_SECRET", "DATABASE_URL"]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
print("ERROR: Missing required environment variables:")
for var in missing_vars:
print(f" - {var}")
print("\nPlease configure these variables in backend/.env")
sys.exit(1)
# Get configuration from environment
API_HOST = os.getenv("API_HOST", "0.0.0.0")
API_PORT = int(os.getenv("PORT", os.getenv("API_PORT", "8000")))
LOG_LEVEL = os.getenv("LOG_LEVEL", "info").lower()
RELOAD = os.getenv("PORT") is None # Disable reload in production (when PORT is set)
print("=" * 60)
print("Starting Todo API Development Server")
print("=" * 60)
print(f"Host: {API_HOST}")
print(f"Port: {API_PORT}")
print(f"Log Level: {LOG_LEVEL}")
print(f"Reload: {RELOAD}")
print("=" * 60)
print(f"\nAPI Documentation: http://{API_HOST}:{API_PORT}/docs")
print(f"Health Check: http://{API_HOST}:{API_PORT}/health")
print("\nPress CTRL+C to stop the server")
print("=" * 60)
# Start uvicorn server
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"src.api.main:app",
host=API_HOST,
port=API_PORT,
reload=RELOAD,
log_level=LOG_LEVEL,
access_log=True
)
|