Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use asgi root path to handle mount point #1723

Merged
merged 3 commits into from
Jan 21, 2025
Merged

Conversation

amol-
Copy link
Contributor

@amol- amol- commented Jan 16, 2025

Changes chainlit server to rely on ASGI root_path variable to know where the application is mounted on.
This addresses both cases where chainlit is proxied to non root paths, mounted as a subapp or both combined.

I tested this by serving the following app

from fastapi import FastAPI
from chainlit.utils import mount_chainlit

app = FastAPI()

@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}

mount_chainlit(app=app, target="clapp.py", path="/chainlit")

served with

uvicorn app:app --host 0.0.0.0 --port 80 --root-path=/proxy

The application is correctly available at http://localhost/proxy/chainlit/ and loads, previously it would not load trying to fetch css and js files from wrong path.

This might also fix #1440 #1707 and #1397 but I didn't have the opportunity to confirm that.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. backend Pertains to the Python backend. labels Jan 16, 2025
@dokterbob
Copy link
Collaborator

Great contrib @amol-! Code looks nice and clean, I've been yearning to clean this up myself for some time now!

I'd like to take a bit of time next week to do manual validation and would love feedback from other users, also on #1440 #1707 and #1397.

@duarteocarmo @alexagr @illegalplumbing @marsanla Does this solve your issue?

@dokterbob
Copy link
Collaborator

dokterbob commented Jan 21, 2025

Review progress

References

Copy link
Collaborator

@dokterbob dokterbob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks GREAT to me! Much needed cleanup of unnecessary complexity!

@dokterbob dokterbob merged commit 4a86512 into Chainlit:main Jan 21, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Pertains to the Python backend. evaluate-with-priority What's needed to address this one? size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chainlit mounting mechanism fails when FastAPI has root_path.
2 participants