-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Custom FastAPI routes no longer work #1819
Comments
I updated the example, the signature of the However, I notice that visiting the root of the app redirect to the Chainlit app, which I would not expect since it is mounted on |
I've managed to work around it, but it isn't pretty. This is what I did: create new init_chainlit.py:
create new main.py:
Without reordering the request to /custom-auth is caught by Path: /{full_path:path}:
With reordering fix:
I know this isn't the correct way of doing it. The custom app in the example you have, mount_chainlit app is overridden in
So all the custom routes are added after the catch all route. That's why I had to inject it in the main app, and reorder the custom route. To start the app I now run main.py which uses If you have another recommendation on how to do it without my fix, I'll test it asap. Took me almost all day yesterday going through why the latest update didn't work with my custom route. But I'm happy to have some more insight how Chainlit works. Thanks for a great product! |
Thank for the insight, we'll fix this so you can remove the workaround! |
@s0l4r I think you got the strategy for adding custom routes wrong! Or, it changed, or something. ;) The recommended strategy is now to mount chainlit into a regular FastAPI app. The FastAPI app will do as it should and it's possible to mix custom endpoints (mounted to the FastAPI app). Unfortunately, the example isn't yet merged but here you go: https://github.com/Chainlit/cookbook/tree/d1c209e2dcdc7d304ae0364d0389688d6ad5a024/reverse_proxy |
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}).
I modified server.py to check if my custom route is activated, but it's caught by the catch all route:
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)
Expected behavior
Custom routes should not be overwritten by Chainlit.
Desktop (please complete the following information):
Additional context
The error might be in how the sub application is mounted, and the changes done in #1723
The text was updated successfully, but these errors were encountered: