Создан пример приложения
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -174,3 +174,5 @@ cython_debug/
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Other
|
||||
.DS_Store
|
||||
|
||||
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Python Debugger: FastAPI",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"module": "uvicorn",
|
||||
"args": [
|
||||
"api.main:app",
|
||||
"--reload"
|
||||
],
|
||||
"jinja": true
|
||||
}
|
||||
]
|
||||
}
|
||||
2
api/__init__.py
Normal file
2
api/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
"""FastAPI application package."""
|
||||
|
||||
24
api/main.py
Normal file
24
api/main.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from api.routers.health import router as health_router
|
||||
|
||||
|
||||
app = FastAPI(title="Common FastAPI App")
|
||||
app.include_router(health_router)
|
||||
|
||||
# Keep permissive defaults; tighten for production deployments.
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("api.main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
|
||||
2
api/routers/__init__.py
Normal file
2
api/routers/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
"""Application routers package."""
|
||||
|
||||
14
api/routers/health.py
Normal file
14
api/routers/health.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
def health() -> dict:
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def root() -> dict:
|
||||
return {"message": "FastAPI is running"}
|
||||
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
Reference in New Issue
Block a user