from fastapi import FastAPI from app.routes import router as api_router from fastapi.middleware.cors import CORSMiddleware from fastapi import FastAPI, HTTPException, Request from fastapi.responses import JSONResponse import logging # Initialize the FastAPI app app = FastAPI( title="API for the DAS Homework", description="This api is is used to serve for the DAS Homework web application", version="1.0.0" ) app.add_middleware( CORSMiddleware, allow_origins=["https://das-prototype.web.app"], allow_credentials=True, allow_methods=["*"], # Allow all HTTP methods (e.g., GET, POST) allow_headers=["*"], # Allow all headers ) logging.basicConfig(level=logging.INFO) @app.middleware("http") async def log_requests(request: Request, call_next): try: body = await request.body() logging.info(f"Request body: {body.decode()}") response = await call_next(request) logging.info(f"Response status: {response.status_code}") return response except Exception as e: logging.error(f"Error occurred: {e}") raise e # Include the API router app.include_router(api_router) @app.get("/") async def root(): return {"message": "API for the DAS Homework"}