Add base path to update endpoint from VS Code
This will make it work regardless of what the current URL happens to be. Also move the telemetry setting into the options since we might as well make use of it seeing as how we have to parse it for the base path anyway.
This commit is contained in:
@ -486,10 +486,10 @@ index eab8591492..26668701f7 100644
|
||||
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
|
||||
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
|
||||
new file mode 100644
|
||||
index 0000000000..3f53907de0
|
||||
index 0000000000..4042e32f74
|
||||
--- /dev/null
|
||||
+++ b/src/vs/server/browser/client.ts
|
||||
@@ -0,0 +1,227 @@
|
||||
@@ -0,0 +1,263 @@
|
||||
+import { Emitter } from 'vs/base/common/event';
|
||||
+import { URI } from 'vs/base/common/uri';
|
||||
+import { localize } from 'vs/nls';
|
||||
@ -507,6 +507,7 @@ index 0000000000..3f53907de0
|
||||
+import 'vs/workbench/contrib/localizations/browser/localizations.contribution';
|
||||
+import { LocalizationsService } from 'vs/workbench/services/localizations/electron-browser/localizationsService';
|
||||
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
|
||||
+import { Options } from 'vs/server/ipc.d';
|
||||
+
|
||||
+class TelemetryService extends TelemetryChannelClient {
|
||||
+ public constructor(
|
||||
@ -516,11 +517,46 @@ index 0000000000..3f53907de0
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * Remove extra slashes in a URL.
|
||||
+ */
|
||||
+export const normalize = (url: string, keepTrailing = false): string => {
|
||||
+ return url.replace(/\/\/+/g, "/").replace(/\/+$/, keepTrailing ? "/" : "");
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * Get options embedded in the HTML from the server.
|
||||
+ */
|
||||
+export const getOptions = <T extends Options>(): T => {
|
||||
+ if (typeof document === "undefined") {
|
||||
+ return {} as T;
|
||||
+ }
|
||||
+ const el = document.getElementById("coder-options");
|
||||
+ try {
|
||||
+ if (!el) {
|
||||
+ throw new Error("no options element");
|
||||
+ }
|
||||
+ const value = el.getAttribute("data-settings");
|
||||
+ if (!value) {
|
||||
+ throw new Error("no options value");
|
||||
+ }
|
||||
+ const options = JSON.parse(value);
|
||||
+ const parts = window.location.pathname.replace(/^\//g, "").split("/");
|
||||
+ parts[parts.length - 1] = options.base;
|
||||
+ const url = new URL(window.location.origin + "/" + parts.join("/"));
|
||||
+ return {
|
||||
+ ...options,
|
||||
+ base: normalize(url.pathname, true),
|
||||
+ };
|
||||
+ } catch (error) {
|
||||
+ console.warn(error);
|
||||
+ return {} as T;
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
+const options = getOptions();
|
||||
+
|
||||
+const TELEMETRY_SECTION_ID = 'telemetry';
|
||||
+
|
||||
+const el = document.getElementById("vscode-disable-telemetry");
|
||||
+const disableTelemetry = el && el.getAttribute("data-value") === "true" || false;
|
||||
+
|
||||
+Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
||||
+ 'id': TELEMETRY_SECTION_ID,
|
||||
+ 'order': 110,
|
||||
@ -530,7 +566,7 @@ index 0000000000..3f53907de0
|
||||
+ 'telemetry.enableTelemetry': {
|
||||
+ 'type': 'boolean',
|
||||
+ 'description': localize('telemetry.enableTelemetry', 'Enable usage data and errors to be sent to a Microsoft online service.'),
|
||||
+ 'default': !disableTelemetry,
|
||||
+ 'default': !options.disableTelemetry,
|
||||
+ 'tags': ['usesOnlineServices']
|
||||
+ }
|
||||
+ }
|
||||
@ -625,7 +661,7 @@ index 0000000000..3f53907de0
|
||||
+ const applyUpdate = async (): Promise<void> => {
|
||||
+ (services.get(ILogService) as ILogService).debug("Applying update...");
|
||||
+
|
||||
+ const response = await fetch("./update/apply", {
|
||||
+ const response = await fetch(normalize(`${options.base}/update/apply`), {
|
||||
+ headers: { "content-type": "application/json" },
|
||||
+ });
|
||||
+ if (response.status !== 200) {
|
||||
@ -643,7 +679,7 @@ index 0000000000..3f53907de0
|
||||
+ const getUpdate = async (): Promise<void> => {
|
||||
+ (services.get(ILogService) as ILogService).debug("Checking for update...");
|
||||
+
|
||||
+ const response = await fetch("./update", {
|
||||
+ const response = await fetch(normalize(`${options.base}/update`), {
|
||||
+ headers: { "content-type": "application/json" },
|
||||
+ });
|
||||
+ if (response.status !== 200) {
|
||||
@ -1076,14 +1112,20 @@ index 0000000000..56331ff1fc
|
||||
+require('../../bootstrap-amd').load('vs/server/entry');
|
||||
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
|
||||
new file mode 100644
|
||||
index 0000000000..a0d1d0df54
|
||||
index 0000000000..15d2ba55d1
|
||||
--- /dev/null
|
||||
+++ b/src/vs/server/ipc.d.ts
|
||||
@@ -0,0 +1,108 @@
|
||||
@@ -0,0 +1,114 @@
|
||||
+/**
|
||||
+ * External interfaces for integration into code-server over IPC. No vs imports
|
||||
+ * should be made in this file.
|
||||
+ */
|
||||
+export interface Options {
|
||||
+ base: string
|
||||
+ commit: string
|
||||
+ disableTelemetry: boolean
|
||||
+ nlsConfiguration: NLSConfiguration
|
||||
+}
|
||||
+
|
||||
+export interface InitMessage {
|
||||
+ type: 'init';
|
||||
|
Reference in New Issue
Block a user