Skip to content

Commit

Permalink
add IS_SUBMOUNT
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed Jun 13, 2024
1 parent 9c61ed4 commit c7cc319
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from watchfiles import awatch

ROOT_PATH = os.environ.get("CHAINLIT_ROOT_PATH", "")
IS_SUBMOUNT = os.environ.get("CHAINLIT_SUBMOUNT", "") == "true"


@asynccontextmanager
Expand Down Expand Up @@ -114,7 +115,7 @@ async def watch_files_for_changes():
logger.error(f"Error reloading module: {e}")

await asyncio.sleep(1)
await socket.emit("reload", {})
await sio.emit("reload", {})

break

Expand Down Expand Up @@ -170,22 +171,24 @@ def get_build_dir(local_target: str, packaged_target: str):

app = FastAPI(lifespan=lifespan)

app.add_middleware(
CORSMiddleware,
allow_origins=config.project.allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
sio = socketio.AsyncServer(
cors_allowed_origins=[] if IS_SUBMOUNT else "*", async_mode="asgi"
)

sio = socketio.AsyncServer(cors_allowed_origins=[], async_mode="asgi")

combined_asgi_app = socketio.ASGIApp(
sio,
app,
socketio_path=f"{ROOT_PATH}/ws/socket.io" if ROOT_PATH else "/ws/socket.io",
)

app.add_middleware(
CORSMiddleware,
allow_origins=config.project.allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

router = APIRouter(prefix=ROOT_PATH)

app.mount(
Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def check_file(target: str):

def mount_chainlit(app: FastAPI, target: str, path="/chainlit"):
os.environ["CHAINLIT_ROOT_PATH"] = path
os.environ["CHAINLIT_SUBMOUNT"] = "true"
from chainlit.config import config, load_module
from chainlit.server import combined_asgi_app as chainlit_app

Expand Down

0 comments on commit c7cc319

Please sign in to comment.