From b73ace3a282b3a0605a6c0c4918d9558d4c8d2b3 Mon Sep 17 00:00:00 2001 From: Yi-Ting Chiu Date: Sat, 14 Dec 2024 17:01:48 -0700 Subject: [PATCH] :bug: Fix: CORS policy issue fuck Added allow all origin in the backend for cors stuff. Also change the way the frontend handles the url so it can be run on weird host --- __init__.py | 2 +- server.py | 11 +++++++++++ static/index.html | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 5a282803..7dd6fda7 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -__version__ = "0.5.0" \ No newline at end of file +__version__ = "0.5.1" \ No newline at end of file diff --git a/server.py b/server.py index 1f6c8a39..a66a504b 100644 --- a/server.py +++ b/server.py @@ -11,6 +11,7 @@ from loguru import logger from fastapi import FastAPI, WebSocket, APIRouter from fastapi.staticfiles import StaticFiles +from starlette.middleware.cors import CORSMiddleware from starlette.websockets import WebSocketDisconnect from main import OpenLLMVTuberMain from live2d_model import Live2dModel @@ -36,8 +37,18 @@ def __init__(self, open_llm_vtuber_main_config: Dict | None = None): """ logger.info(f"t41372/Open-LLM-VTuber, version {__init__.__version__}") self.app = FastAPI() + # Add CORS middleware + self.app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) self.router = APIRouter() self.connected_clients: List[WebSocket] = [] + + self.open_llm_vtuber_main_config = open_llm_vtuber_main_config # Initialize model manager diff --git a/static/index.html b/static/index.html index 0ab2ff45..692c730b 100644 --- a/static/index.html +++ b/static/index.html @@ -325,6 +325,10 @@ break; case "set-model": console.log("set-model: ", message.text); + + model_url = this.wsUrl.value.replace("ws:", window.location.protocol).replace("/client-ws", "") + message.text.url; + message.text.url = model_url; + live2dModule.init().then(() => { live2dModule.loadModel(message.text); });