added the lost ip address to accepted cors origins

This commit is contained in:
Saifeddine ALOUI 2024-02-25 18:25:54 +01:00
parent f96fb8f263
commit 35969f6414
2 changed files with 20 additions and 1 deletions

19
app.py
View File

@ -28,6 +28,19 @@ from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from pydantic import BaseModel, ValidationError
from fastapi.encoders import jsonable_encoder
import socket
import psutil
def get_ip_addresses():
hostname = socket.gethostname()
ip_addresses = [socket.gethostbyname(hostname)]
for interface_name, interface_addresses in psutil.net_if_addrs().items():
for address in interface_addresses:
if str(address.family) == 'AddressFamily.AF_INET':
ip_addresses.append(address.address)
return ip_addresses
app = FastAPI(title="LoLLMS", description="This is the LoLLMS-Webui API documentation")
@ -64,6 +77,12 @@ if __name__ == "__main__":
is_https = False
# Create a Socket.IO server
if config["host"]!="localhost":
if config["host"]!="0.0.0.0":
config.allowed_origins += config["host"]
else:
config.allowed_origins += get_ip_addresses()
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=config.allowed_origins+[f"https://localhost:{config['port']}" if is_https else f"http://localhost:{config['port']}"], ping_timeout=1200, ping_interval=30) # Enable CORS for selected origins
LOLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, args=args, sio=sio)

@ -1 +1 @@
Subproject commit d205fe80c7cb65ef0b563977592a21e71de4ad73
Subproject commit f941e8d231533370b8786dbe2987b399498caecc