diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..5181f34 --- /dev/null +++ b/app/main.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI(title="FastAPI Server") + + +@app.get("/") +def read_root(): + return {"status": "ok"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..364e2ee --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn[standard] diff --git a/scripts/start-fastapi.sh b/scripts/start-fastapi.sh new file mode 100755 index 0000000..89414db --- /dev/null +++ b/scripts/start-fastapi.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: ./scripts/start-fastapi.sh [--host 0.0.0.0] [--port 8000] [--reload] +# Requires: uvicorn (pip install uvicorn[standard]) and fastapi + +HOST="127.0.0.1" +PORT="8000" +RELOAD="" + +while [[ $# -gt 0 ]]; do + case $1 in + --host) + HOST="$2"; shift 2 ;; + --port) + PORT="$2"; shift 2 ;; + --reload) + RELOAD="--reload"; shift ;; + *) + echo "Unknown argument: $1" >&2; exit 1 ;; + esac +done + +# Detect available Python interpreter +if command -v python3 >/dev/null 2>&1; then + PYTHON_BIN="python3" +elif command -v python >/dev/null 2>&1; then + PYTHON_BIN="python" +else + echo "Python interpreter not found. Please install Python 3." >&2 + exit 127 +fi + +# Prefer invoking uvicorn as a module to avoid PATH issues +exec "$PYTHON_BIN" -m uvicorn app.main:app --host "$HOST" --port "$PORT" $RELOAD