Skip to content

Commit

Permalink
🐛 Fix: CORS policy issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
t41372 committed Dec 15, 2024
1 parent 14aa264 commit b73ace3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
11 changes: 11 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit b73ace3

Please sign in to comment.