allow usage of latest fastapi
This commit is contained in:
parent
94ffa9fc53
commit
29ce0bf4f2
@ -27,4 +27,4 @@ GitPython==3.1.30
|
|||||||
torchsde==0.2.5
|
torchsde==0.2.5
|
||||||
safetensors==0.2.7
|
safetensors==0.2.7
|
||||||
httpcore<=0.15
|
httpcore<=0.15
|
||||||
fastapi==0.90.1
|
fastapi==0.94.0
|
||||||
|
12
webui.py
12
webui.py
@ -183,13 +183,16 @@ def initialize():
|
|||||||
signal.signal(signal.SIGINT, sigint_handler)
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
|
||||||
|
|
||||||
def setup_cors(app):
|
def setup_middleware(app):
|
||||||
|
app.middleware_stack = None # reset current middleware to allow modifying user provided list
|
||||||
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
if cmd_opts.cors_allow_origins and cmd_opts.cors_allow_origins_regex:
|
if cmd_opts.cors_allow_origins and cmd_opts.cors_allow_origins_regex:
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_origin_regex=cmd_opts.cors_allow_origins_regex, allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_origin_regex=cmd_opts.cors_allow_origins_regex, allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
||||||
elif cmd_opts.cors_allow_origins:
|
elif cmd_opts.cors_allow_origins:
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
||||||
elif cmd_opts.cors_allow_origins_regex:
|
elif cmd_opts.cors_allow_origins_regex:
|
||||||
app.add_middleware(CORSMiddleware, allow_origin_regex=cmd_opts.cors_allow_origins_regex, allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
app.add_middleware(CORSMiddleware, allow_origin_regex=cmd_opts.cors_allow_origins_regex, allow_methods=['*'], allow_credentials=True, allow_headers=['*'])
|
||||||
|
app.build_middleware_stack() # rebuild middleware stack on-the-fly
|
||||||
|
|
||||||
|
|
||||||
def create_api(app):
|
def create_api(app):
|
||||||
@ -213,8 +216,7 @@ def api_only():
|
|||||||
initialize()
|
initialize()
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
setup_cors(app)
|
setup_middleware(app)
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
||||||
api = create_api(app)
|
api = create_api(app)
|
||||||
|
|
||||||
modules.script_callbacks.app_started_callback(None, app)
|
modules.script_callbacks.app_started_callback(None, app)
|
||||||
@ -271,9 +273,7 @@ def webui():
|
|||||||
# running its code. We disable this here. Suggested by RyotaK.
|
# running its code. We disable this here. Suggested by RyotaK.
|
||||||
app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
|
app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
|
||||||
|
|
||||||
setup_cors(app)
|
setup_middleware(app)
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
||||||
|
|
||||||
modules.progress.setup_progress_api(app)
|
modules.progress.setup_progress_api(app)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user