XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add support for CORS preflight OPTION requests (#2006)

8a8a9597
foxfire52 <foxfire52@virgilio.it>
提交于

代码差异

1 个文件 +9 -1
Modified g4f/api/__init__.py +9 -1
@@ -12,6 +12,7 @@ from fastapi.security import APIKeyHeader
12 12 from starlette.exceptions import HTTPException
13 13 from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN
14 14 from fastapi.encoders import jsonable_encoder
15 from fastapi.middleware.cors import CORSMiddleware
15 16 from pydantic import BaseModel
16 17 from typing import Union, Optional
17 18
@@ -24,6 +25,13 @@ from g4f.cookies import read_cookie_files
24 25 def create_app():
25 26 app = FastAPI()
26 27 api = Api(app)
28 app.add_middleware(
29 CORSMiddleware,
30 allow_origin_regex=".*",
31 allow_credentials=True,
32 allow_methods=["*"],
33 allow_headers=["*"],
34 )
27 35 api.register_routes()
28 36 api.register_authorization()
29 37 api.register_validation_exception_handler()
@@ -232,4 +240,4 @@ def run_api(
232 240 use_colors=use_colors,
233 241 factory=True,
234 242 reload=debug
235 )
243 )