This commit is contained in:
JiriUhlir
2026-06-18 11:58:23 +02:00
parent 284e013753
commit 6934f22253
18 changed files with 1367 additions and 17 deletions
+43 -16
View File
@@ -1,25 +1,52 @@
"""analytics - stateless API proxy for Google Analytics (GA4) and Sklik.
Runs behind the AppFactory Caddy reverse proxy at /apps/<app-id>. ROOT_PATH is
injected as an env var; FastAPI's ``root_path`` makes Swagger UI and the OpenAPI
``servers`` use the proxy prefix so "Try it out" hits /apps/<app-id>/... .
The service stores no secrets. Every credential is supplied per request in an
X- header and used only to talk to the upstream API (see AGENTS.md and
``app.credentials``).
"""
import os
from fastapi import FastAPI
APP_NAME = os.getenv("APP_NAME", "analytics")
APP_VERSION = os.getenv("APP_VERSION", "1.0.0")
from . import config
from .errors import register_exception_handlers
from .logging_config import get_logger
from .routers import ga_admin, ga_data, meta, sklik
logger = get_logger(__name__)
ROOT_PATH = os.getenv("ROOT_PATH", "")
DESCRIPTION = """
Stateless proxy exposing **Google Analytics 4** and **Sklik** (Seznam) APIs.
All credentials are passed per request as `X-` headers (never stored):
* **Google Analytics** — `X-GA-Access-Token` (preferred) or `X-GA-Credentials`
(base64 service-account JSON). Optional `X-GA-Quota-Project`.
* **Sklik** — `X-Sklik-Token`. Optional `X-Sklik-User-Id` for managed accounts.
See `documentation/` in the repository for details.
""".strip()
app = FastAPI(
title=APP_NAME,
version=APP_VERSION,
root_path=ROOT_PATH
title=config.APP_NAME,
version=config.APP_VERSION,
description=DESCRIPTION,
root_path=ROOT_PATH,
)
@app.get("/health")
def health():
return {"status": "ok"}
register_exception_handlers(app)
@app.get("/version")
def version():
return {
"app": APP_NAME,
"version": APP_VERSION,
"language": "python",
"root_path": ROOT_PATH
}
app.include_router(meta.router)
app.include_router(ga_data.router)
app.include_router(ga_admin.router)
app.include_router(sklik.router)
logger.info(
"analytics started (version=%s, root_path=%r)", config.APP_VERSION, ROOT_PATH
)