Skip to content

Commit

Permalink
Merge pull request #2281 from foxfire52/main
Browse files Browse the repository at this point in the history
Add support for CORS preflight OPTIONS requests (#2006)
  • Loading branch information
xtekky authored Oct 22, 2024
2 parents ed95563 + 8a8a959 commit 6a1f88e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from starlette.exceptions import HTTPException
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN
from fastapi.encoders import jsonable_encoder
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import Union, Optional

Expand All @@ -24,6 +25,13 @@
def create_app():
app = FastAPI()
api = Api(app)
app.add_middleware(
CORSMiddleware,
allow_origin_regex=".*",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
api.register_routes()
api.register_authorization()
api.register_validation_exception_handler()
Expand Down

0 comments on commit 6a1f88e

Please sign in to comment.