53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""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
|
|
|
|
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=config.APP_NAME,
|
|
version=config.APP_VERSION,
|
|
description=DESCRIPTION,
|
|
root_path=ROOT_PATH,
|
|
)
|
|
|
|
register_exception_handlers(app)
|
|
|
|
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
|
|
)
|