theia icon indicating copy to clipboard operation
theia copied to clipboard

Set bind url

Open cjchristopher opened this issue 6 years ago • 9 comments

Description

I've looked just about everywhere I can think and can't find if there is an option for this. Having followed the install steps here: https://theia-ide.org/docs/composing_applications/ I am running Theia behind a reverse proxy (nginx), but alongside other apps. I would ideally like to access it at localhost/theia (as opposed to the root of localhost), but I can find no way to specify the bind point. nginx is correctly forwarding requests on localhost/theia to localhost:3000, but I receive a "Cannot GET" error.

Is this possible?

cjchristopher avatar Mar 02 '20 02:03 cjchristopher

@cjchristopher I am not sure whether anybody manages it. Express.js has middleware, maybe there is a way to specify the root path.

akosyakov avatar Mar 02 '20 08:03 akosyakov

Right. Seems related to https://github.com/eclipse-theia/theia/issues/6844 as well.

I'm digging around Theia and can't see an obvious place to set this for Express - could any contributor point me in the right direction?

cjchristopher avatar Mar 03 '20 03:03 cjchristopher

I've searched also right now and could not find anything. It seems that Express.js does not allow to change the base path vis the middleware. I wonder what would be the minimal change to allow alternative base path in Theia backend application.

akosyakov avatar Mar 03 '20 08:03 akosyakov

Alternatively we state that it is not supported and one can use a proxy always.

akosyakov avatar Mar 03 '20 08:03 akosyakov

I did find some evidence that you can set the base path in Express, I just couldn't locate where in the Theia codebase I would add that call. Although potentially I am misunderstanding your explicit meaning when you say "via the middleware"

See: https://stackoverflow.com/questions/42902739/express-app-change-base-url and https://stackoverflow.com/a/5994334

cjchristopher avatar Mar 03 '20 22:03 cjchristopher

In Theia you will need to implement BackendApplicationContribution with the custom extension. There is configure lifecycle hook to configure the express application.

akosyakov avatar Mar 04 '20 07:03 akosyakov

@cjchristopher I ran into the same problem I think. When you look at the GET request, is it sending the get request to the expected url? For example localhost:3000/index.js? I ran into an issue where it would pass the path wrong and I had to add a rewrite rule in order to pass the correct URL.

Maybe try adding rewrite ^/theia/(.*) /$1 break; to your location block.

OwenMatsuda avatar Apr 10 '20 03:04 OwenMatsuda

Is there anything new?

liuchintao avatar May 20 '21 07:05 liuchintao

@cjchristopher I ran into the same problem I think. When you look at the GET request, is it sending the get request to the expected url? For example localhost:3000/index.js? I ran into an issue where it would pass the path wrong and I had to add a rewrite rule in order to pass the correct URL.

Maybe try adding rewrite ^/theia/(.*) /$1 break; to your location block.

This worked for me. My nginx config:


    server {
        listen 443 ssl;
        ...

        rewrite ^/theia/(.*) /$1 break;

        location / {
            proxy_pass http://host.docker.internal:3000;  // I was using docker in mac, so added `http://host.docker.internal`, you can use `http://localhost` for your case.
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

    }

bhawanishiv-techolution avatar Apr 12 '24 10:04 bhawanishiv-techolution