90 lines
2.3 KiB
Python
90 lines
2.3 KiB
Python
#!/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 argparse
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import uvicorn
|
|
|
|
# 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() |