(# API Uvicorn Server

This document explains how to run the FastAPI ASGI frontdoor that mounts the
legacy Flask WSGI server under `/legacy` and exposes the mission FastAPI
router at `/api/missions`.

Quick start (development):

1. Ensure your working directory is the repo root (where `main.py` lives):

```bash
cd /home/github_bgilbert1984_NerfEngine/NerfEngine
```

2. Run Uvicorn with the project on `PYTHONPATH` so local modules import correctly:

```bash
PYTHONPATH=$(pwd) python3 -m uvicorn main:app --host 0.0.0.0 --port 8000 --log-level info
```

Notes:
- The FastAPI frontdoor will mount the existing Flask app at `/legacy` (and
	at `/` for legacy `/api/*` routes) while the FastAPI `missions` router
	serves `/api/missions/*` directly.
- Example endpoints after startup:
	- GET `/`  → FastAPI health/info
	- `/api/missions/*` → FastAPI mission namespace
	- `/api/*` → legacy Flask endpoints (mounted via WSGIMiddleware)

Running as a background service (simple):

```bash
PYTHONPATH=$(pwd) nohup python3 -m uvicorn main:app --host 0.0.0.0 --port 8000 --log-level info > /tmp/uvicorn_main.log 2>&1 & echo $! > /tmp/uvicorn_main.pid
```

Check logs:

```bash
tail -n 200 /tmp/uvicorn_main.log
```

Stopping the server (if started with the pid file):

```bash
kill $(cat /tmp/uvicorn_main.pid) || true
```

Testing the combined stack (smoke):

1. Register/login an operator via the legacy `/api/operator` endpoints.
2. Use the provided smoke script to create/join a mission and capture SSE diffs:

```bash
MISSION_ID=<existing-mission-id> TOKEN=<operator-session-token> /home/github_bgilbert1984_NerfEngine/NerfEngine/tools/smoke_emit_and_listen.sh localhost 8000 10
```

If you prefer to run the FastAPI missions namespace as a standalone microservice
instead of mounting it, run:

```bash
PYTHONPATH=$(pwd) python3 -m uvicorn missions_api_fastapi:app --host 0.0.0.0 --port 8001 --log-level info
```

Then either proxy `/api/missions/*` from Flask to the FastAPI service, or keep
both running and call the appropriate host/port from clients.

Security:
- For production, run behind a reverse proxy (nginx) and enable TLS.
- Add process supervision (systemd) and proper log rotation.

This file is intentionally brief — refer to the repo README for more
operational details.
)
