summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2024-10-22 23:28:04 +0200
committerGitHub <noreply@github.com>2024-10-22 23:28:04 +0200
commit6a1f88e7b74883b7f59f3a9259ee8d19b805280b (patch)
tree26f6b8ee7cf686cdeabacb4788c340513fef69a2 /g4f
parentMerge pull request #2291 from nikmosi/main (diff)
parentAdd support for CORS preflight OPTION requests (#2006) (diff)
downloadgpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar.gz
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar.bz2
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar.lz
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar.xz
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.tar.zst
gpt4free-6a1f88e7b74883b7f59f3a9259ee8d19b805280b.zip
Diffstat (limited to 'g4f')
-rw-r--r--g4f/api/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py
index da35319a..83df469a 100644
--- a/g4f/api/__init__.py
+++ b/g4f/api/__init__.py
@@ -12,6 +12,7 @@ from fastapi.security import APIKeyHeader
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
@@ -24,6 +25,13 @@ from g4f.cookies import read_cookie_files
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()