feat(api): Initialize FastAPI app with health check
This commit is contained in:
0
src/ea_chatbot/api/__init__.py
Normal file
0
src/ea_chatbot/api/__init__.py
Normal file
25
src/ea_chatbot/api/main.py
Normal file
25
src/ea_chatbot/api/main.py
Normal 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)
|
||||||
0
src/ea_chatbot/api/routers/__init__.py
Normal file
0
src/ea_chatbot/api/routers/__init__.py
Normal file
9
tests/api/test_main.py
Normal file
9
tests/api/test_main.py
Normal 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"}
|
||||||
Reference in New Issue
Block a user