Init
This commit is contained in:
parent
604ee83631
commit
d3e990384d
9 changed files with 118 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
|||
.idea
|
||||
*.iml
|
||||
uv.lock
|
||||
|
||||
__pycache__/
|
||||
**/dist/
|
||||
|
|
|
|||
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
4
app/__main__.py
Normal file
4
app/__main__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
if __name__ == '__main__':
|
||||
from main import run
|
||||
|
||||
run()
|
||||
0
app/api/__init__.py
Normal file
0
app/api/__init__.py
Normal file
8
app/api/v1.py
Normal file
8
app/api/v1.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/", summary="Main API")
|
||||
async def root():
|
||||
return {"message": "Witaj w API v12"}
|
||||
29
app/main.py
Normal file
29
app/main.py
Normal file
|
|
@ -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)
|
||||
39
app/templates/index.html
Normal file
39
app/templates/index.html
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>{{ title }}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<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>
|
||||
36
pyproject.toml
Normal file
36
pyproject.toml
Normal file
|
|
@ -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"
|
||||
1
run.sh
Normal file
1
run.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
uv run uvicorn app.main:app --reload
|
||||
Loading…
Add table
Add a link
Reference in a new issue