chainlit
chainlit copied to clipboard
Custom FastAPI routes no longer work
Describe the bug After upgrade from 2.0.2 to 2.0.603 I cannot get custom routes to work, for example https://github.com/Chainlit/cookbook/tree/main/custom-frontend/backend. I've been trying to create the custom endpoint /custom-auth, but the route is never reached.
I believe this may have been introduced in https://github.com/Chainlit/chainlit/pull/1723/files?diff=split&w=0
The custom route is now overwritten of routes by the chainlit catch-all route (e.g., /{full_path:path}).
INFO: 127.0.0.1:62200 - "GET /custom-auth HTTP/1.1" 200 OK
Intercepted path: custom-auth
I modified server.py to check if my custom route is activated, but it's caught by the catch all route:
@router.get("/{full_path:path}")
async def serve(full_path: str, request: Request):
"""Serve the UI files."""
print(f"Intercepted path: {full_path}")
html_template = get_html_template(request.scope["root_path"])
response = HTMLResponse(content=html_template, status_code=200)
return response
This results in that the default html template is being rendered when I try to access /custom-auth.
To Reproduce Steps to reproduce the behavior:
Run the example at https://github.com/Chainlit/cookbook/tree/main/custom-frontend/backend with custom auth.
I tried starting the app using the new root-path parameter, but still doesn't work (also tried without --root-path set)
"args": [
"run",
"--root-path=/chainlit",
"-h",
"app.py"
]
Expected behavior Custom routes should not be overwritten by Chainlit.
Desktop (please complete the following information):
- OS: MacOS
- Browser Chrome
- Version 131.0.6778.265
Additional context
The error might be in how the sub application is mounted, and the changes done in #1723
mount_chainlit(app=app, target="cl-app.py", path="/chainlit"