Skip to content

Local development and debugging

This page covers running cms-api on your machine without Docker. The service is a plain Python 3.12 FastAPI app started with uvicorn from src/cms_api/main.py.

Prerequisites

Requirement Notes
Python 3.12 .python-version pins 3.12; pyproject.toml requires >=3.12,<3.13.
AWS credentials Needed when ENVIRONMENT=local (reads staging secrets via fs_config).
hq on PYTHONPATH Required for live DB access. The workspace layout (<workspace>/hq/) satisfies this when you run from the org folder.
Redis + MySQL Resolved from Secrets Manager for ENVIRONMENT=local (staging paths). Tests use in-memory stubs instead.

One-time setup

cd cms-api
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt -r requirements_dev.txt

If you need the CMS schema models locally, ensure the workspace root is on PYTHONPATH (the parent folder that contains both cms-api/ and hq/):

export PYTHONPATH="/path/to/frontstory:${PYTHONPATH:-}"

Run the API locally

export ENVIRONMENT=local
export PYTHONPATH="/path/to/frontstory:${PYTHONPATH:-}"
python src/cms_api/main.py

The app factory boots uvicorn on port 8080. Verify:

curl -s localhost:8080/api/status
# {"status":"OK"}

With CHECK_DB=1 in the environment, the health endpoint also reports database reachability.

What ENVIRONMENT=local does

config/cfg.py resolves secrets from staging paths (/stg/...) but never requires production AWS roles. Missing non-critical secrets fall back to deterministic dev defaults so the process can boot; missing critical secrets in prd/stg are fatal.

Setting Typical local source
SECRET_KEY Secrets Manager /common/cms-api/secret-key
PREVIEW_SECRET /common/cms-api/preview-secret (optional; ?version returns 503 if absent)
Redis /<env>/shared/redis + Param Store /<env>/cms-api/redis-db
CMS DB hq.cms.db.config → /stg/mysql/skynet-harvester for local/stg

Run tests (no AWS)

The test suite sets ENVIRONMENT=test automatically (via conftest.py / env). It never calls Secrets Manager and does not need Redis or MySQL:

pytest
# or a single module:
pytest tests/test_health.py -q

ENVIRONMENT=test uses os.environ overrides and a fixed non-prod SECRET_KEY.

Debugging tips

Logging

FastAPI/uvicorn log level follows the uvicorn defaults. For request tracing, add logging in the store or route you are investigating; the app uses standard library logging (no custom wrapper).

Common breakpoints

Symptom Where to look
401 on /admin/v1/* authentication/utils.py — JWT + Redis session validation
403 on /public/v2/* authentication/worker.py — bearer WORKER_API_KEY
503 on ?version preview PREVIEW_SECRET not loaded; check Secrets Manager
DB connection errors datastore/db.py, hq.cms.db.config; confirm PYTHONPATH includes hq
Store returns empty public/store/sql.py vs memory.py — which store is wired in tests vs local

IDE debugging

Run src/cms_api/main.py as a Python module with ENVIRONMENT=local and PYTHONPATH set. Set breakpoints in the route handler or store method under src/cms_api/.

Preview mode (v2)

Editor preview uses ?_preview=<secret> plus optional ?_ver=<id>. The secret must match PREVIEW_SECRET (header X-CMS-Preview for version reads). Preview requests bypass all caches in the worker; locally you can hit v2 endpoints directly with the worker API key:

export WORKER_API_KEY="$(aws secretsmanager get-secret-value ...)"  # or from stg secret
curl -H "Authorization: Bearer $WORKER_API_KEY" \
  "http://localhost:8080/public/v2/sites/WK/settings"

Build these docs locally

python3.12 -m venv .venv_docs && source .venv_docs/bin/activate
pip install -r requirements_docs.txt
mkdocs build --strict
mkdocs serve   # http://127.0.0.1:8000/