Mirrowel commited on
Commit
30f6fec
·
1 Parent(s): 3083d86

feat(api): ✨ add CORS middleware to allow cross-origin requests

Browse files
Files changed (1) hide show
  1. src/proxy_app/main.py +10 -0
src/proxy_app/main.py CHANGED
@@ -4,6 +4,7 @@ import asyncio
4
  import os
5
  from contextlib import asynccontextmanager
6
  from fastapi import FastAPI, Request, HTTPException, Depends
 
7
  from fastapi.responses import StreamingResponse
8
  from fastapi.security import APIKeyHeader
9
  from dotenv import load_dotenv
@@ -155,6 +156,15 @@ async def lifespan(app: FastAPI):
155
 
156
  # --- FastAPI App Setup ---
157
  app = FastAPI(lifespan=lifespan)
 
 
 
 
 
 
 
 
 
158
  api_key_header = APIKeyHeader(name="Authorization", auto_error=False)
159
 
160
  def get_rotating_client(request: Request) -> RotatingClient:
 
4
  import os
5
  from contextlib import asynccontextmanager
6
  from fastapi import FastAPI, Request, HTTPException, Depends
7
+ from fastapi.middleware.cors import CORSMiddleware
8
  from fastapi.responses import StreamingResponse
9
  from fastapi.security import APIKeyHeader
10
  from dotenv import load_dotenv
 
156
 
157
  # --- FastAPI App Setup ---
158
  app = FastAPI(lifespan=lifespan)
159
+
160
+ # Add CORS middleware to allow all origins, methods, and headers
161
+ app.add_middleware(
162
+ CORSMiddleware,
163
+ allow_origins=["*"], # Allows all origins
164
+ allow_credentials=True,
165
+ allow_methods=["*"], # Allows all methods
166
+ allow_headers=["*"], # Allows all headers
167
+ )
168
  api_key_header = APIKeyHeader(name="Authorization", auto_error=False)
169
 
170
  def get_rotating_client(request: Request) -> RotatingClient: