Skip to content

Commit 329acbb

Browse files
committed
Combine main and webview servers
1 parent fd55139 commit 329acbb

5 files changed

Lines changed: 26 additions & 39 deletions

File tree

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ VOLUME [ "/home/coder/project" ]
5757

5858
COPY --from=0 /src/build/code-server /usr/local/bin/code-server
5959
EXPOSE 8443
60-
EXPOSE 8444
6160

6261
ENTRYPOINT ["dumb-init", "code-server", "--host", "0.0.0.0"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ remote server, accessible through the browser.
55

66
Try it out:
77
```bash
8-
docker run -it -p 127.0.0.1:8443:8443 -p 127.0.0.1:8444:8444 -v "$PWD:/home/coder/project" codercom/code-server
8+
docker run -it -p 127.0.0.1:8443:8443 -v "$PWD:/home/coder/project" codercom/code-server
99
```
1010

1111
- Code on your Chromebook, tablet, and laptop with a consistent dev environment.

scripts/vscode.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,19 @@ index 4d8a5d6907..b464d5276f 100644
12471247
template.decorationIcon.title = resource.decorations.tooltip || '';
12481248
} else {
12491249
template.decorationIcon.style.display = 'none';
1250+
diff --git a/src/vs/workbench/contrib/webview/browser/pre/main.js b/src/vs/workbench/contrib/webview/browser/pre/main.js
1251+
index a6be033e07..a4dcb7357a 100644
1252+
--- a/src/vs/workbench/contrib/webview/browser/pre/main.js
1253+
+++ b/src/vs/workbench/contrib/webview/browser/pre/main.js
1254+
@@ -355,7 +355,7 @@
1255+
// seeing the service worker applying properly.
1256+
// Fake load an empty on the correct origin and then write real html
1257+
// into it to get around this.
1258+
- newFrame.src = `/fake.html?id=${ID}`;
1259+
+ newFrame.src = `fake.html?id=${ID}`;
1260+
}
1261+
newFrame.style.cssText = 'display: block; margin: 0; overflow: hidden; position: absolute; width: 100%; height: 100%; visibility: hidden';
1262+
document.body.appendChild(newFrame);
12501263
diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts
12511264
index 6d4d096a9c..bbb7930e7a 100644
12521265
--- a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts

src/cli.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { buildHelpMessage, buildVersionMessage, options } from "vs/platform/envi
77
import pkg from "vs/platform/product/node/package";
88
import product from "vs/platform/product/node/product";
99

10-
import { AuthType, MainServer, WebviewServer } from "vs/server/src/server";
10+
import { AuthType, MainServer } from "vs/server/src/server";
1111
import "vs/server/src/tar";
1212
import { buildAllowedMessage, generateCertificate, generatePassword, open, unpackExecutables } from "vs/server/src/util";
1313

@@ -22,8 +22,6 @@ interface Args extends ParsedArgs {
2222
open?: string;
2323
port?: string;
2424
socket?: string;
25-
"webview-port"?: string;
26-
"webview-socket"?: string;
2725
}
2826

2927
// The last item is _ which is like -- so our options need to come before it.
@@ -57,13 +55,11 @@ options.push({ id: "cert", type: "string", cat: "o", description: "Path to certi
5755
options.push({ id: "cert-key", type: "string", cat: "o", description: "Path to the certificate's key if one was provided." });
5856
options.push({ id: "extra-builtin-extensions-dir", type: "string", cat: "o", description: "Path to an extra builtin extension directory." });
5957
options.push({ id: "extra-extensions-dir", type: "string", cat: "o", description: "Path to an extra user extension directory." });
60-
options.push({ id: "host", type: "string", cat: "o", description: "Host for the main and webview servers." });
58+
options.push({ id: "host", type: "string", cat: "o", description: "Host for the server." });
6159
options.push({ id: "auth", type: "string", cat: "o", description: `The type of authentication to use. ${buildAllowedMessage(AuthType)}.` });
6260
options.push({ id: "open", type: "boolean", cat: "o", description: "Open in the browser on startup." });
6361
options.push({ id: "port", type: "string", cat: "o", description: "Port for the main server." });
6462
options.push({ id: "socket", type: "string", cat: "o", description: "Listen on a socket instead of host:port." });
65-
options.push({ id: "webview-port", type: "string", cat: "o", description: "Port for the webview server." });
66-
options.push({ id: "webview-socket", type: "string", cat: "o", description: "Listen on a socket instead of host:port." });
6763

6864
options.push(last);
6965

@@ -140,26 +136,17 @@ const main = async (): Promise<void> => {
140136
options.certKey = certKey;
141137
}
142138

143-
const webviewPort = args["webview-port"];
144-
const webviewServer = new WebviewServer({
145-
...options,
146-
port: typeof webviewPort !== "undefined" && parseInt(webviewPort, 10) || 8444,
147-
socket: args["webview-socket"],
148-
});
149-
150139
const server = new MainServer({
151140
...options,
152141
port: typeof args.port !== "undefined" && parseInt(args.port, 10) || 8443,
153142
socket: args.socket,
154-
}, webviewServer, args);
143+
}, args);
155144

156-
const [webviewAddress, serverAddress, /* ignore */] = await Promise.all([
157-
webviewServer.listen(),
145+
const [serverAddress, /* ignore */] = await Promise.all([
158146
server.listen(),
159147
unpackExecutables(),
160148
]);
161-
console.log(`Main server listening on ${serverAddress}`);
162-
console.log(`Webview server listening on ${webviewAddress}`);
149+
console.log(`Server listening on ${serverAddress}`);
163150

164151
if (options.auth && !process.env.PASSWORD) {
165152
console.log(" - Password is", options.password);

src/server.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ export abstract class Server {
121121
public constructor(options: ServerOptions) {
122122
this.options = {
123123
host: options.auth && options.cert ? "0.0.0.0" : "localhost",
124-
basePath: options.basePath ? options.basePath.replace(/\/+$/, "") : "",
125124
...options,
125+
basePath: options.basePath ? options.basePath.replace(/\/+$/, "") : "",
126126
};
127127
this.protocol = this.options.cert ? "https" : "http";
128128
if (this.protocol === "https") {
@@ -154,7 +154,7 @@ export abstract class Server {
154154
/**
155155
* The local address of the server. If you pass in a request, it will use the
156156
* request's host if listening on a port (rather than a socket). This enables
157-
* accessing the webview server from the same host as the main server.
157+
* setting the webview endpoint to the same host the browser is using.
158158
*/
159159
public address(request?: http.IncomingMessage): string {
160160
const address = this.server.address();
@@ -357,11 +357,7 @@ export class MainServer extends Server {
357357
private readonly services = new ServiceCollection();
358358
private readonly servicesPromise: Promise<void>;
359359

360-
public constructor(
361-
options: ServerOptions,
362-
private readonly webviewServer: WebviewServer,
363-
args: ParsedArgs,
364-
) {
360+
public constructor(options: ServerOptions, args: ParsedArgs) {
365361
super(options);
366362
this.server.on("upgrade", async (request, socket) => {
367363
const protocol = this.createProtocol(request, socket);
@@ -398,6 +394,9 @@ export class MainServer extends Server {
398394
case "/out":
399395
return this.getResource(path.join(this.rootPath, base, requestPath));
400396
case "/resources": return this.getResource(requestPath);
397+
case "/webview":
398+
const webviewPath = path.join(this.rootPath, "out/vs/workbench/contrib/webview/browser/pre");
399+
return this.getResource(path.join(webviewPath, requestPath || "/index.html"));
401400
default: throw new HttpError("Not found", HttpCode.NotFound);
402401
}
403402
}
@@ -406,11 +405,10 @@ export class MainServer extends Server {
406405
const filePath = path.join(this.rootPath, "out/vs/code/browser/workbench/workbench.html");
407406
let [content] = await Promise.all([
408407
util.promisify(fs.readFile)(filePath, "utf8"),
409-
this.webviewServer.listen(),
410408
this.servicesPromise,
411409
]);
412410

413-
const webviewEndpoint = this.webviewServer.address(request);
411+
const webviewEndpoint = this.address(request) + "/webview/";
414412
const cwd = process.env.VSCODE_CWD || process.cwd();
415413
const workspacePath = parsedUrl.query.workspace as string | undefined;
416414
const folderPath = !workspacePath ? parsedUrl.query.folder as string | undefined || this.options.folderUri || cwd: undefined;
@@ -567,13 +565,3 @@ export class MainServer extends Server {
567565
return undefined;
568566
}
569567
}
570-
571-
export class WebviewServer extends Server {
572-
protected async handleRequest(
573-
base: string,
574-
requestPath: string,
575-
): Promise<Response> {
576-
const webviewPath = path.join(this.rootPath, "out/vs/workbench/contrib/webview/browser/pre");
577-
return this.getResource(path.join(webviewPath, base, requestPath || "/index.html"));
578-
}
579-
}

0 commit comments

Comments
 (0)