mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-12 13:38:33 +03:00
Format and lint web directory (#67)
This commit is contained in:
@@ -6,7 +6,7 @@ from fastapi.staticfiles import StaticFiles
|
||||
from loguru import logger
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
|
||||
from app.shared.settings import get_settings
|
||||
from app.shared.settings import Settings, get_settings
|
||||
from app.shared.task_messaging import get_celery
|
||||
from app.web.config import API_DESCRIPTION, VERSION
|
||||
from app.web.endpoints.default import default_router
|
||||
@@ -21,13 +21,22 @@ from app.web.security import token_api_key_auth
|
||||
|
||||
celery = get_celery()
|
||||
|
||||
def app_factory(settings = get_settings()):
|
||||
|
||||
def app_factory(settings: Settings = None):
|
||||
# TODO: Create dev, test, and prod versions of settings that do not have
|
||||
# TODO: to be passed in as a parameter
|
||||
if settings is None:
|
||||
settings = get_settings()
|
||||
|
||||
app = FastAPI(
|
||||
title="Auto-Archiver API",
|
||||
description=API_DESCRIPTION,
|
||||
version=VERSION,
|
||||
contact={"name": "GitHub", "url": "https://github.com/bellingcat/auto-archiver-api"},
|
||||
lifespan=lifespan
|
||||
contact={
|
||||
"name": "GitHub",
|
||||
"url": "https://github.com/bellingcat/auto-archiver-api",
|
||||
},
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
@@ -46,14 +55,30 @@ def app_factory(settings = get_settings()):
|
||||
app.include_router(interoperability_router)
|
||||
|
||||
# prometheus exposed in /metrics with authentication
|
||||
Instrumentator(should_group_status_codes=False, excluded_handlers=["/metrics", "/health", "/openapi.json", "/favicon.ico"]).instrument(app).expose(app, dependencies=[Depends(token_api_key_auth)])
|
||||
Instrumentator(
|
||||
should_group_status_codes=False,
|
||||
excluded_handlers=[
|
||||
"/metrics",
|
||||
"/health",
|
||||
"/openapi.json",
|
||||
"/favicon.ico",
|
||||
],
|
||||
).instrument(app).expose(app, dependencies=[Depends(token_api_key_auth)])
|
||||
|
||||
if settings.SERVE_LOCAL_ARCHIVE:
|
||||
local_dir = settings.SERVE_LOCAL_ARCHIVE
|
||||
if not os.path.isdir(local_dir) and os.path.isdir(local_dir.replace("/app", ".")):
|
||||
if not os.path.isdir(local_dir) and os.path.isdir(
|
||||
local_dir.replace("/app", ".")
|
||||
):
|
||||
local_dir = local_dir.replace("/app", ".")
|
||||
if len(settings.SERVE_LOCAL_ARCHIVE) > 1 and os.path.isdir(local_dir):
|
||||
logger.warning(f"MOUNTing local archive, use this in development only {settings.SERVE_LOCAL_ARCHIVE}")
|
||||
app.mount(settings.SERVE_LOCAL_ARCHIVE, StaticFiles(directory=local_dir), name=settings.SERVE_LOCAL_ARCHIVE)
|
||||
logger.warning(
|
||||
f"MOUNTing local archive, use this in development only {settings.SERVE_LOCAL_ARCHIVE}"
|
||||
)
|
||||
app.mount(
|
||||
settings.SERVE_LOCAL_ARCHIVE,
|
||||
StaticFiles(directory=local_dir),
|
||||
name=settings.SERVE_LOCAL_ARCHIVE,
|
||||
)
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user