43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from injectable import load_injection_container
|
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
|
|
from app.api.v1 import router as api_v1_router
|
|
from app.config import get_settings
|
|
from app.core.core import WebhookProcessor
|
|
|
|
# Inicjalizacja Jinja2
|
|
templates_env = Environment(
|
|
loader=FileSystemLoader("app/templates"),
|
|
autoescape=select_autoescape(["html", "xml"]),
|
|
)
|
|
|
|
app = FastAPI(title="Karl", version="0.1.0")
|
|
|
|
# Rejestracja routera API pod /api/v1
|
|
app.include_router(api_v1_router, prefix="/api/v1", tags=["v1"])
|
|
# app.add_event_handler()
|
|
|
|
load_injection_container()
|
|
webhook_service = WebhookProcessor()
|
|
print(webhook_service.health)
|
|
|
|
|
|
# Przykładowy endpoint HTML
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def index(request: Request) -> HTMLResponse:
|
|
template = templates_env.get_template("index.html")
|
|
html = template.render(title="Strona główna", request=request)
|
|
return HTMLResponse(content=html)
|
|
|
|
|
|
def run() -> None:
|
|
import uvicorn
|
|
settings = get_settings()
|
|
uvicorn.run(
|
|
"app.main:app",
|
|
host=settings.app.host,
|
|
port=settings.app.port,
|
|
reload=settings.app.reload,
|
|
)
|