Add CORS middleware for allowing all origins to make requests
This commit is contained in:
13
main.py
13
main.py
@@ -13,6 +13,9 @@ from functools import lru_cache
|
|||||||
from crawl4ai.database import get_total_count, clear_db
|
from crawl4ai.database import get_total_count, clear_db
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
# Import the CORS middleware
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
|
||||||
# Task management
|
# Task management
|
||||||
tasks = {}
|
tasks = {}
|
||||||
@@ -25,6 +28,16 @@ lock = asyncio.Lock()
|
|||||||
|
|
||||||
app = FastAPI()
|
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
|
# Mount the pages directory as a static directory
|
||||||
app.mount("/pages", StaticFiles(directory=__location__ + "/pages"), name="pages")
|
app.mount("/pages", StaticFiles(directory=__location__ + "/pages"), name="pages")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user