diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43d6028 --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Virtual environments +.venv/ +venv/ +ENV/ +env/ + +# Environment variables +.env +.env.local + +# Database files +*.db +*.sqlite +*.sqlite3 + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# Testing +.pytest_cache/ +.coverage +htmlcov/ + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Logs +*.log diff --git a/README.md b/README.md index b0217c3..ab4004e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # LifeLine-ICT +![CI](https://github.com/buayism/LifeLine-ICT/actions/workflows/ci.yml/badge.svg) + ## Project Summary LifeLine-ICT is a digital infrastructure management platform that supports the diff --git a/backend/app/main.py b/backend/app/main.py index 6a33ed0..f2ac099 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -7,6 +7,7 @@ """ from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware from .core.config import settings from .core.logging import configure_logging @@ -56,6 +57,15 @@ def create_app() -> FastAPI: errors.register_exception_handlers(app) + # Configure CORS for frontend integration + app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) + app.include_router(projects_router) app.include_router(resources_router) app.include_router(locations_router) @@ -65,7 +75,13 @@ def create_app() -> FastAPI: app.include_router(alert_router) app.include_router(auth_router) - @app.get("/health", tags=["health"]) + @app.get("/", tags=["root"]) + async def root_redirect(): + """Redirect root URL to API documentation.""" + from fastapi.responses import RedirectResponse + return RedirectResponse(url="/docs") + + @app.get("/api/v1/health", tags=["health"]) async def healthcheck() -> dict[str, str]: """ Provide a basic health indicator confirming application availability. diff --git a/backend/tests/api/test_health.py b/backend/tests/api/test_health.py new file mode 100644 index 0000000..8fdfe6f --- /dev/null +++ b/backend/tests/api/test_health.py @@ -0,0 +1,17 @@ +"""Tests for the health check endpoint.""" + +from fastapi.testclient import TestClient + + +def test_health_check_returns_ok(client: TestClient) -> None: + """Health endpoint should return status ok.""" + response = client.get("/api/v1/health") + assert response.status_code == 200 + assert response.json() == {"status": "ok"} + + +def test_root_redirects_to_docs(client: TestClient) -> None: + """Root URL should redirect to API documentation.""" + response = client.get("/", follow_redirects=False) + assert response.status_code == 307 + assert response.headers["location"] == "/docs"