From aa126e436b9d4a4b41c8be9c90c4938425774f39 Mon Sep 17 00:00:00 2001 From: ntohidi Date: Fri, 10 May 2024 12:27:40 +0200 Subject: [PATCH] Add CORS middleware for allowing all origins to make requests --- main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.py b/main.py index d75f81cb..71b43c36 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,9 @@ from functools import lru_cache from crawl4ai.database import get_total_count, clear_db import os import uuid +# Import the CORS middleware +from fastapi.middleware.cors import CORSMiddleware + # Task management tasks = {} @@ -25,6 +28,16 @@ lock = asyncio.Lock() app = FastAPI() +# CORS configuration +origins = ["*"] # Allow all origins +app.add_middleware( + CORSMiddleware, + allow_origins=origins, # List of origins that are allowed to make requests + allow_credentials=True, + allow_methods=["*"], # Allows all methods + allow_headers=["*"], # Allows all headers +) + # Mount the pages directory as a static directory app.mount("/pages", StaticFiles(directory=__location__ + "/pages"), name="pages")