feat: scaffold FastAPI backend with config and health endpoint
This commit is contained in:
parent
954f7ac367
commit
f9c612927a
12
backend/Dockerfile
Normal file
12
backend/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY app ./app
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
0
backend/app/__init__.py
Normal file
0
backend/app/__init__.py
Normal file
16
backend/app/config.py
Normal file
16
backend/app/config.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class Settings:
|
||||||
|
def __init__(self):
|
||||||
|
self.minio_endpoint = os.environ.get("MINIO_ENDPOINT", "localhost:9000")
|
||||||
|
self.minio_access_key = os.environ.get("MINIO_ACCESS_KEY", "minioadmin")
|
||||||
|
self.minio_secret_key = os.environ.get("MINIO_SECRET_KEY", "minioadmin")
|
||||||
|
self.minio_bucket = os.environ.get("MINIO_BUCKET", "dochub")
|
||||||
|
self.meilisearch_host = os.environ.get("MEILISEARCH_HOST", "http://localhost:7700")
|
||||||
|
self.meilisearch_api_key = os.environ.get("MEILISEARCH_API_KEY", "")
|
||||||
|
self.meilisearch_index = os.environ.get("MEILISEARCH_INDEX", "documents")
|
||||||
|
self.cors_origins = os.environ.get("CORS_ORIGINS", "*").split(",")
|
||||||
|
|
||||||
|
|
||||||
|
settings = Settings()
|
||||||
19
backend/app/main.py
Normal file
19
backend/app/main.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
from app.config import settings
|
||||||
|
|
||||||
|
app = FastAPI(title="DocHub API")
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=settings.cors_origins,
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
def health():
|
||||||
|
return {"status": "ok"}
|
||||||
2
backend/pytest.ini
Normal file
2
backend/pytest.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[pytest]
|
||||||
|
pythonpath = .
|
||||||
7
backend/requirements.txt
Normal file
7
backend/requirements.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fastapi==0.115.0
|
||||||
|
uvicorn[standard]==0.30.6
|
||||||
|
minio==7.2.9
|
||||||
|
meilisearch==0.31.5
|
||||||
|
pytest==8.3.3
|
||||||
|
httpx==0.27.2
|
||||||
|
python-multipart==0.0.9
|
||||||
11
backend/tests/test_main.py
Normal file
11
backend/tests/test_main.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
from app.main import app
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
|
def test_health_returns_ok():
|
||||||
|
response = client.get("/health")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"status": "ok"}
|
||||||
Loading…
Reference in New Issue
Block a user