chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Chainlit unusable under proxy with request rewriting

Open akamya997 opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug Using version 1.1.302, I tried to deploy it using docker on certain cloud service. But it can only return a blank page while working well on my local machine. The service URL is like http://example.com/some/endpoint, but chainlit is trying to get the assets from http://example.com/assets/..., thus returning a blank page and making it unusable. Unfortunately, it is not the case that can be solved by the --root-path config which is merged in #1064. I found that this problem is caused by request rewriting, see the following for more details.

To Reproduce I have also tried to reproduce this problem in a local environment using Nginx.

  1. Use nginx to set up a proxy using a server config like
server {
    listen 8080 default_server;
    listen [::]:8080 default_server;
    server_name _;

    location /endpoint {
            rewrite ^/endpoint/(.*)$ /$1 break;
            proxy_pass http://localhost:9000;
    }
}
  1. Set up chainlit service using demo.py like chainlit run demo.py -w --port 9000
  2. Visit http://localhost:8080/endpoint and see a blank page

Expected behavior Chainlit works well under proxy with request rewriting.

Screenshots There are some screenshots from local test.

  1. Successfully get the html file under proxy

  2. Failed to get assets due to wrong prefix, the assets should be under /endpoint/assets

Additional context As a temporary solution, I hard coded the root-path for frontend only, which means that I modified the following lines to make it works for me: https://github.com/Chainlit/chainlit/blob/abf4108424b48b3a92b1b71479956b7e46ba772f/backend/chainlit/server.py#L279 https://github.com/Chainlit/chainlit/blob/abf4108424b48b3a92b1b71479956b7e46ba772f/backend/chainlit/server.py#L309-L311

akamya997 avatar Jun 20 '24 14:06 akamya997