Skip to content

Configure web server base path#202491

Merged
aeschli merged 15 commits intomainfrom
aeschli/serverRootPath
Feb 23, 2024
Merged

Configure web server base path#202491
aeschli merged 15 commits intomainfrom
aeschli/serverRootPath

Conversation

@aeschli
Copy link
Contributor

@aeschli aeschli commented Jan 15, 2024

Adds a new server option --server-base-path that allows to configure the URL path under which the web server is started,

@vishaltak
Copy link

@aeschli - Wanted to understand if this is being worked on and if there is any target for this? Thanks for working on this.

@aeschli aeschli marked this pull request as ready for review February 23, 2024 20:15
@aeschli aeschli added this to the March 2024 milestone Feb 23, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file about, do we need this committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. Removed it

@ab077u
Copy link

ab077u commented Mar 22, 2024

Thanks for this feature. I was trying to figure out how to make this subpath work with using nginx, until I stumbled on this.

I am trying out the following insiders build, and found some issue with themes and icon rendering. One observation is if I start the server without --server-base-path option and access it, then start with --server-base-path it renders properly. In addition, the welcome screen walkthroughs icons for installed extensions fail to load (screenshots below).

code-insiders serve-web --server-base-path /foo/bar --port 8883 --host 0.0.0.0 --without-connection-token --log debug                                                      
image
Version: 1.88.0-insider (Universal)
Commit: b40321263dbe14515f436b9b34ab5c7d8d5526ae
Date: 2024-03-21T17:26:53.619Z
Electron: 28.2.6
ElectronBuildId: 27476517
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.2.0

image

@mering
Copy link
Contributor

mering commented Mar 23, 2024

Thanks for this great feature. Is there a way to only set it as proxy path in a sense that additional resources get loaded with this prefix but the server answers to requests without this prefix?

For example, I have a proxy which redirects "/a/b" to "code_servce_web_container:8080", so additional resources need to be loaded from "/a/b/path" while the code server should respond on "/path".

Or even better: If one would use relative paths everywhere this would not be necessary.

@oakaigh
Copy link
Contributor

oakaigh commented Mar 23, 2024

additional resources get loaded with this prefix but the server answers to requests without this prefix

@mering Is there no way for the proxy server to be configured to strip the prefix? (Edit: path stripping outside the code server is not supported) Implementing automatic prefix stripping on the code server itself can be tricky, particularly since it wasn't designed to be very flexible at path handling.

Relative paths were actually possible in the original PR; but the biggest problem is that the resources aren't loaded and served relative to the page URL in the HTML. Embedding the resources and serving everything in a single HTML would sure eliminate the need for prefixes though.

@mering
Copy link
Contributor

mering commented Mar 23, 2024

@oakaigh The proxy server does handle and strip the prefix and this is exactly the problem:
When accessing /prefix/devcontainer the proxy redirects this to vscode:port/devcontainer which succeeds but it tries to download the resources from /insider-ID/static/out/... instead of /prefix/insider-ID/static/out/... so the proxy doesn't know where to forward the request to.
image

Embedding would indeed solve the problem.

I am looking for something like Coder's VSCODE_PROXY_URI (patch).

@mering
Copy link
Contributor

mering commented Mar 23, 2024

@oakaigh Can you explain why relative paths don't work?
A relative path ./insider-ID/static/out/... referenced from the main page / should be the same as /insider-ID/static/out/..., no?

@oakaigh
Copy link
Contributor

oakaigh commented Mar 23, 2024

@mering

The proxy server does handle and strip the prefix and this is exactly the problem

Apologize for the confusion. I stand corrected - actually the paths need to be passed to the server as is. So no, the paths cannot be stripped outside the code server - unless there's an option to enable the server to return HTMLs with stripped resource paths (so that it's informed of the stripped paths). I don't think this is currently implemented anywhere.

A relative path ./insider-ID/static/out/... referenced from the main page / should be the same as /insider-ID/static/out/..., no?

The problem is that the main page may not always be /, and the code server serves resources on absolute, non-wildcard paths.

@aeschli
Copy link
Contributor Author

aeschli commented Mar 25, 2024

@oakaigh @mering Can we discuss this in a new issue?
Re missing icons: Last week I fixed and issue about icon loading. #208359
So please make sure you test this in the latest insiders.

@mering
Copy link
Contributor

mering commented Apr 15, 2024

@aeschli I created a new issue in #210399.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants