microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.55k stars 29.4k forks source link

Allow web server behind proxy #210399

Open mering opened 7 months ago

mering commented 7 months ago

It would be great if one could run web server behind a proxy. Currently, it doesn't find assets correctly. There are several options to solve this:

  1. Using paths relative to the page where they are loaded from
  2. Allow the user to set a prefix (this is the approach Coder follows with VSCODE_PROXY_URI environment variable and patch)

The current implementation of base path (#165391, #202491) is not sufficient as I explained in https://github.com/microsoft/vscode/pull/202491#issuecomment-2016531665 and following.

aeschli commented 7 months ago

Can you be more specific what has to change? Feel free to provide a PR.

mering commented 7 months ago

@aeschli basically serving the pages from/ instead of base path while keeping all links prefixed by base path.

mering commented 7 months ago

@aeschli it could be that something like #210455 is enough.

Unfortunately, I couldn't test this. I tried getting a testing environment on main branch:

mering commented 7 months ago

For testing one should be able to use a nginx reverse proxy with the following config:

server {
    listen 80;
    listen [::]:80;

    location /some/path/ {
      proxy_pass http://localhost:8080/;
      proxy_set_header Host $http_host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

where 8080 is the port of code cli.

cjangrist-givedirectly commented 7 months ago

+1 for this, thanks ya'll. would be incredible to serve it behind jupyter proxy (that's also behind cloudflare proxy). The full availability of extensions is 🔑 for our users

jhgoebbert commented 7 months ago

+1 from my side, too. We would love to add VSCode as a webapp to our portal.
But it would need to run behind a proxy accessible at a special dynamically generated url which is user and login specific.

michaelneely commented 6 months ago

+1 from me. I'm trying to run VSCode serve web in a container within a VPC so that I have network access to other resources. Due to limitations, I can only run on some-url/subfolder with a reverse proxy to my container.

Nginx config of @mering got me some of the way there. I added a sub_filter to rewrite static assets to /subfolder (hacky, I know), which fixed the 404s. Now I'm getting websocket connections error. Unfortunately, I don't think it's possible to rewrite web socket connection paths via nginx as well. That would require modifying the code directly.

michaelneely commented 6 months ago

@aeschli it could be that something like #210455 is enough.

Unfortunately, I couldn't test this. I tried getting a testing environment on main branch:

  • Running ./scripts/code-cli.sh serve-web
  • First, I encountered Cargo missing #210454 when running in the Devcontainer.
  • After manually installing Rust within the container, I only get error error getting latest version: Updates are are not available: no configured quality.

@mering from what I can tell, your change seems to work. Serving at / with assets at whatever the server-base-path is

Screenshot 2024-05-01 at 16 26 55

mering commented 4 months ago

@michaelneely how did you get past "error error getting latest version: Updates are are not available: no configured quality"?

I spent the whole day trying to get a testing environment on main but everything I tried (code-cli.sh, cargo, gulp compile-cli, ...), I always get stuck at this error. When setting VSCODE_CLI_QUALITY=insiders this downloads the frontend part instead of using it from my branch.

michaelneely commented 4 months ago

@mering I just manually updated the .js file in the running web server with your change.