diff --git a/.gitignore b/.gitignore index 03079c7..790a54f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea *.iml +uv.lock __pycache__/ **/dist/ diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__main__.py b/app/__main__.py new file mode 100644 index 0000000..0b3284c --- /dev/null +++ b/app/__main__.py @@ -0,0 +1,4 @@ +if __name__ == '__main__': + from main import run + + run() diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/v1.py b/app/api/v1.py new file mode 100644 index 0000000..1cd9f50 --- /dev/null +++ b/app/api/v1.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/", summary="Main API") +async def root(): + return {"message": "Witaj w API v12"} diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..22fe12a --- /dev/null +++ b/app/main.py @@ -0,0 +1,29 @@ +from fastapi import FastAPI, Request +from fastapi.responses import HTMLResponse +from jinja2 import Environment, FileSystemLoader, select_autoescape + +from app.api.v1 import router as api_v1_router + +# 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"]) + + +# 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 + uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True) diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..ebbe8ca --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,39 @@ + + +
+ +To jest prosta strona Jinja2 serwowana przez FastAPI.
+Uruchamianie serwera lokalnie: uv run app lub uv run uvicorn app.main:app --reload