Skip to content

Commit

Permalink
Issue pinecone-io#284 Add CORS support to handle preflight OPTIONS re…
Browse files Browse the repository at this point in the history
…quests

This commit addresses the CORS issue reported in Issue pinecone-io#284, where the API failed to handle preflight OPTIONS requests, causing failures in direct client-to-API communications from browsers. The FastAPI application now includes CORSMiddleware, allowing proper handling of CORS preflight checks and enabling browser-based clients to directly interface with the Canopy API.

Changes:
- Added CORSMiddleware to the FastAPI application setup.
- Configured the middleware to allow all origins, methods, and headers, facilitating cross-origin requests.

This update ensures better accessibility and integration capabilities of the Canopy API for various client applications, especially those running in browser environments.
  • Loading branch information
kowshik24 committed Mar 11, 2024
1 parent 448450a commit d889683
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/canopy_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
Body,
APIRouter
)

from fastapi.middleware.cors import (
CORSMiddleware
)
import uvicorn
from typing import cast, Union, Optional

Expand Down Expand Up @@ -89,6 +93,15 @@ async def lifespan(app: FastAPI):
},
lifespan=lifespan
)

app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)

openai_api_router = APIRouter()
context_api_router = APIRouter(prefix="/context")
application_router = APIRouter(tags=["Application"])
Expand Down

0 comments on commit d889683

Please sign in to comment.