Skip to content

Commit 120750f

Browse files
committed
fix(webClientServer): include basePath in createRequestUrl
This patches the createRequestUrl convenience method to ensure that the basePath is included in the returned URL in case code-server is being served behind a reverse proxy. An example of this would be using Caddy to server code-server on localhost:8082/code/ This fix ensures request urls are created against localhost:8082/code/ instead of localhost:8082/
1 parent 8db6c9b commit 120750f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/vs/server/webClientServer.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ export class WebClientServer {
164164
private createRequestUrl(req: http.IncomingMessage, parsedUrl: url.UrlWithParsedQuery, pathname: string): URL {
165165
const pathPrefix = getPathPrefix(parsedUrl.pathname!);
166166
const remoteAuthority = this.getRemoteAuthority(req);
167-
return new URL(path.join('/', pathPrefix, pathname), remoteAuthority);
167+
/**
168+
* Prepend URL with basePath.
169+
*
170+
* This ensures the request URL includes the correct base
171+
* in case code-server is being served behind a reverse proxy.
172+
* @author coder
173+
*/
174+
const basePath = new URL(req.headers.referer || 'https://example.com').pathname.slice(0, -1);
175+
176+
return new URL(path.join(basePath, '/', pathPrefix, pathname), remoteAuthority);
168177
}
169178

170179
private _iconSizes = [192, 512];

0 commit comments

Comments
 (0)