diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82adb58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +venv diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/__main__.py b/backend/__main__.py new file mode 100644 index 0000000..ec749c7 --- /dev/null +++ b/backend/__main__.py @@ -0,0 +1,32 @@ +from distutils.sysconfig import get_python_lib +from fastapi import FastAPI +from fastapi.responses import FileResponse +from fastapi.staticfiles import StaticFiles +from backend.health_router import router +from uvicorn import run + + +def create_app(): + app = FastAPI( + title="Backend Server", + ) + app.include_router(router) + + client_path = f"{get_python_lib()}/vite_project" + app.mount("/assets", StaticFiles(directory=f"{client_path}/assets"), name="assets") + app.mount("/static", StaticFiles(directory=f"{client_path}/static"), name="static") + + @app.get("/{catchall:path}") + async def serve_react_app(catchall: str): + return FileResponse(f"{client_path}/index.html") + + return app + + +def main(): + app = create_app() + run(app, host="0.0.0.0", port=8080) + + +if __name__ == "__main__": + main() diff --git a/backend/health_router.py b/backend/health_router.py new file mode 100644 index 0000000..7c1575f --- /dev/null +++ b/backend/health_router.py @@ -0,0 +1,26 @@ +from typing import Literal +from typing_extensions import TypedDict +from fastapi import APIRouter, status + +STATUS = Literal["success", "error", "partial", "unknown"] + + +class ReturnHealthcheckStruct(TypedDict): + status: STATUS + + +router = APIRouter( + prefix="/v1/health-check", + tags=["Health Check"], +) + + +@router.get( + "/liveness", + summary="Perform a Liveness Health Check", + response_description="Return HTTP Status Code 200 (OK)", + status_code=status.HTTP_200_OK, + response_model=ReturnHealthcheckStruct, +) +async def liveness() -> ReturnHealthcheckStruct: + return {"status": "success"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ed0071f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi==0.110.0 +uvicorn==0.29.0 +vite-project==1.0.5