feat(api): Initialize FastAPI app with health check

This commit is contained in:
Yunxiao Xu
2026-02-10 03:25:37 -08:00
parent 60cc401246
commit 60429e1adc
4 changed files with 34 additions and 0 deletions

View File

View File

@@ -0,0 +1,25 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI(
title="Election Analytics Chatbot API",
description="Backend API for the LangGraph-based Election Analytics Chatbot",
version="0.1.0"
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Adjust for production
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/health")
async def health_check():
return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)

View File

9
tests/api/test_main.py Normal file
View File

@@ -0,0 +1,9 @@
from fastapi.testclient import TestClient
from ea_chatbot.api.main import app
client = TestClient(app)
def test_health_check():
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}