code-server: [Bug]: Proxying using {{port}}-{{host}} does not work

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: Firefox
  • Local OS: MacOS
  • Remote OS: Ubuntu 22.04
  • Remote Architecture: amd64
  • code-server --version: 4.15.0 daac46b3cf5901466410ec7df4eabfb0d9ab384a with Code 1.80.1

Steps to Reproduce

To avoid re-creating certs for different domains and sub-domains, I’ve tried to prepend the port to the URL instead of using it as a sub-domain.

  1. Using VSCODE_PROXY_URI=https://{{port}}-{{host}}, if code-server is running on code.example.com, then port 9000 should work on 9000-code.example.com. This is similar to how Gitpod does it.

  2. Setup nginx to read 9000-code.example.com and proxy_pass it to port 9000, NOT the port code-server is running on. If you proxy_pass it to the code_server port, it will just open code-server.

  3. Open python -m http.server 9000 inside code-server. You will see the popup with the proxy URL.

The proxy URL will work but it’s only because of nginx, not because it’s being proxied through code-server.

Expected

It should be proxied through code-server and require cookies and stuff, by proxying to the code-server port (and not port 9000 as seen above).

Actual

Proxying to the code-server port simply opens code-server again instead of the proxied request.

Proxying to the actual port creates a public URL which forwards the requests to the correct port but WITHOUT actually going through code-server. On the running Python server, I also see a 404 response from GET /_static/out/browser/serviceWorker.js but I don’t know why this happens.

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

While this currently works for my setup, it looks like a bug and I’m not sure if the “fix” is stable long term. My only goal is to use {{ port }}-{{ host }} instead of {{ port }}.{{ host }} so if anyone has suggestions, I’m open to them.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

You aren’t activating the internal reverse proxy functionality, therefore it does not work.

You can start code-server like this: ./code-server --proxy-domain {{port}}-{{host}}, then it should work as you expected.

this would require a more complex flow, because of general cookie policies.

  1. 9000.code.example.com/[path]
  2. redirect to code.example.com/login
  3. user authenticates (or is already authenticated)
  4. redirect to 9000.code.example.com/code with an authorization code
  5. /code must validate that code and set a cookie accordingly
  6. redirect back to 9000.code.example.com/[path]

Benefit: For the user, the authentication process can be skipped in most cases as he is already authenticated on the coder-server editor. So no password input required. But I’m not sure if it’s worth the effort.