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 @@ + + + + + {{ title }} + + + + +

{{ title }}

+

To jest prosta strona Jinja2 serwowana przez FastAPI.

+ +

Uruchamianie serwera lokalnie: uv run app lub uv run uvicorn app.main:app --reload

+ + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5185ae8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,36 @@ +[project] +name = "Karl" +version = "0.1.0" +description = "Because name 'Jenkins' was already taken. Greatest composer ever." +readme = "README.md" +requires-python = ">=3.12" +authors = [{ name = "Piotr Dec" }] +dependencies = [ + "fastapi>=0.115.0", + "uvicorn[standard]>=0.30.0", + "jinja2>=3.1.4", +] + +[project.optional-dependencies] +dev = [ + "httpx>=0.27.0", + "pytest>=8.3.0", + "pytest-asyncio>=0.23.0", + "ruff>=0.6.0", + "mypy>=1.11.0", + "types-Jinja2>=2.11.9", +] + +[project.scripts] +app = "app.main:run" + +[tool.uv] +# uv automatycznie wykrywa dependencies z [project] +# Możesz dodać tu własne ustawienia cache/mirrors, jeśli potrzebne. + +[tool.ruff] +line-length = 120 +target-version = "py312" + +[tool.pytest.ini_options] +asyncio_mode = "auto" diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..c65ef75 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +uv run uvicorn app.main:app --reload