Merge branch 'reorder' into dockerify

# Conflicts:
#	Dockerfile
#	app/api/v1.py
#	run.sh
#	src/karl/core/router.py
#	tests/test_mo.py
This commit is contained in:
Piotr Dec 2025-12-03 22:08:15 +01:00
commit 8962c1c168
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0
34 changed files with 730 additions and 25 deletions

View file

View file

@ -1,77 +0,0 @@
import logging
from fastapi import FastAPI
from injectable import load_injection_container
from app.config import get_settings
from app.util.logging import HandlerFactory
class KarlApplication:
from starlette.types import Receive, Scope, Send
def __init__(self) -> None:
self._set_logging()
load_injection_container()
_app = FastAPI(title="Karl", version="0.1.0")
self._set_middlewares(_app)
self._set_routes(_app)
self._set_events(_app)
self._app = _app
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
await self._app.__call__(scope, receive, send)
def _set_logging(self):
settings = get_settings()
logging.addLevelName(5, "TRACE")
logging.Logger.trace = lambda s, msg, *args, **kwargs: s.log(5, msg, *args, **kwargs)
logging.basicConfig(level=settings.logging.level,
handlers=HandlerFactory.create(HandlerFactory.Target.ALL, handler_prefix='karl.',
file_path=settings.logging.path))
loggers = (
"uvicorn",
"uvicorn.access",
"uvicorn.error",
"fastapi",
"asyncio",
"starlette",
)
external_handlers = HandlerFactory.create(HandlerFactory.Target.ALL, file_path=settings.logging.path)
for logger_name in loggers:
logging_logger = logging.getLogger(logger_name)
logging_logger.handlers = external_handlers
logging_logger.propagate = False
def _set_middlewares(self, app: FastAPI):
from app.web.middlewares import LoggingMiddleware
app.add_middleware(LoggingMiddleware)
def _set_routes(self, app: FastAPI):
from app.core.router import router as core_router
app.include_router(core_router)
from app.api.v1 import router as api_v1_router
app.include_router(api_v1_router, prefix="/api/v1", tags=["v1"])
pass
def _set_events(self, app: FastAPI):
pass
def run():
return KarlApplication()
if __name__ == "__main__":
import uvicorn
settings = get_settings()
uvicorn.run(
"app.main:run",
factory=True,
host=settings.app.host,
port=settings.app.port,
reload=settings.app.reload,
log_config=None,
)

View file

@ -1,39 +0,0 @@
<!doctype html>
<html lang="pl">
<head>
<meta charset="utf-8"/>
<title>{{ title }}</title>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<style>
body {
font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
margin: 2rem;
}
code {
background: #f4f4f4;
padding: 0.2rem 0.4rem;
border-radius: 4px;
}
a {
color: #0b5fff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>{{ title }}</h1>
<p>To jest prosta strona Jinja2 serwowana przez FastAPI.</p>
<ul>
<li>UI OpenAPI: <a href="/docs">/docs</a></li>
<li>OpenAPI JSON: <a href="/openapi.json">/openapi.json</a></li>
<li>API v1: <a href="/api/v1/">/api/v1/</a></li>
</ul>
<p>Uruchamianie serwera lokalnie: <code>uv run app</code> lub <code>uv run uvicorn app.main:app --reload</code></p>
</body>
</html>