diff --git a/ci/build.ts b/ci/build.ts index 302696d5..ada4a2cb 100644 --- a/ci/build.ts +++ b/ci/build.ts @@ -339,17 +339,24 @@ class Builder { } private createBundler(out = "dist", commit?: string): Bundler { - return new Bundler(path.join(this.rootPath, "src/browser/pages/app.ts"), { - cache: true, - cacheDir: path.join(this.rootPath, ".cache"), - detailedReport: true, - minify: !!process.env.MINIFY, - hmr: false, - logLevel: 1, - outDir: path.join(this.rootPath, out), - publicUrl: `/static-${commit}/dist`, - target: "browser", - }) + return new Bundler( + [ + path.join(this.rootPath, "src/browser/pages/app.ts"), + path.join(this.rootPath, "src/browser/register.ts"), + path.join(this.rootPath, "src/browser/serviceWorker.ts"), + ], + { + cache: true, + cacheDir: path.join(this.rootPath, ".cache"), + detailedReport: true, + minify: !!process.env.MINIFY, + hmr: false, + logLevel: 1, + outDir: path.join(this.rootPath, out), + publicUrl: `/static-${commit || "development"}/dist`, + target: "browser", + }, + ) } } diff --git a/src/browser/media/manifest.json b/src/browser/media/manifest.json index d2e3db90..c0f5cf23 100644 --- a/src/browser/media/manifest.json +++ b/src/browser/media/manifest.json @@ -12,7 +12,7 @@ "sizes": "96x96" }, { - "src": "/{{BASE}}/static-{{COMMIT}}/src/browser/media/pwa-icon-128.png", + "src": "{{BASE}}/static-{{COMMIT}}/src/browser/media/pwa-icon-128.png", "type": "image/png", "sizes": "128x128" }, diff --git a/src/browser/pages/app.html b/src/browser/pages/app.html index 6f23348c..0e850eee 100644 --- a/src/browser/pages/app.html +++ b/src/browser/pages/app.html @@ -19,6 +19,7 @@ + diff --git a/src/browser/pages/app.ts b/src/browser/pages/app.ts index f4990195..4922dc2d 100644 --- a/src/browser/pages/app.ts +++ b/src/browser/pages/app.ts @@ -8,8 +8,5 @@ import "./login.css" import "./update.css" const options = getOptions() -const parts = window.location.pathname.replace(/^\//g, "").split("/") -parts[parts.length - 1] = options.base -const url = new URL(window.location.origin + "/" + parts.join("/")) -console.log(url) +console.log(options) diff --git a/src/browser/pages/error.html b/src/browser/pages/error.html index 4c8419ad..e714c922 100644 --- a/src/browser/pages/error.html +++ b/src/browser/pages/error.html @@ -16,6 +16,7 @@ /> +
@@ -29,5 +30,6 @@
+ diff --git a/src/browser/pages/home.html b/src/browser/pages/home.html index 1e38bc49..139963ad 100644 --- a/src/browser/pages/home.html +++ b/src/browser/pages/home.html @@ -60,5 +60,6 @@ + diff --git a/src/browser/pages/login.html b/src/browser/pages/login.html index 40ed2f44..b9a8bd6d 100644 --- a/src/browser/pages/login.html +++ b/src/browser/pages/login.html @@ -8,7 +8,7 @@ /> code-server login @@ -19,6 +19,7 @@ /> +
@@ -52,6 +53,7 @@
+ diff --git a/src/browser/pages/vscode.html b/src/browser/pages/vscode.html index f2e323f8..c95918c2 100644 --- a/src/browser/pages/vscode.html +++ b/src/browser/pages/vscode.html @@ -41,6 +41,8 @@ + + @@ -91,6 +93,7 @@ "vs/nls": nlsConfig, } + /g, "") } - return { - ...response, - content: response.content - .replace(/{{COMMIT}}/g, options.commit) - .replace(/{{BASE}}/g, this.base(route)) - .replace(/{{VS_BASE}}/g, this.base(route) + this.options.base) - .replace(`"{{REMOTE_USER_DATA_URI}}"`, `'${JSON.stringify(options.remoteUserDataUri)}'`) - .replace(`"{{PRODUCT_CONFIGURATION}}"`, `'${JSON.stringify(options.productConfiguration)}'`) - .replace(`"{{WORKBENCH_WEB_CONFIGURATION}}"`, `'${JSON.stringify(options.workbenchWebConfiguration)}'`) - .replace(`"{{NLS_CONFIGURATION}}"`, `'${JSON.stringify(options.nlsConfiguration)}'`), - } + response.content = response.content + .replace(/{{VS_BASE}}/g, this.base(route) + this.options.base) + .replace(`"{{REMOTE_USER_DATA_URI}}"`, `'${JSON.stringify(options.remoteUserDataUri)}'`) + .replace(`"{{PRODUCT_CONFIGURATION}}"`, `'${JSON.stringify(options.productConfiguration)}'`) + .replace(`"{{WORKBENCH_WEB_CONFIGURATION}}"`, `'${JSON.stringify(options.workbenchWebConfiguration)}'`) + .replace(`"{{NLS_CONFIGURATION}}"`, `'${JSON.stringify(options.nlsConfiguration)}'`) + return this.replaceTemplates(route, response) } /** diff --git a/src/node/http.ts b/src/node/http.ts index 99fa47e7..a6a329c2 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -12,7 +12,7 @@ import * as tarFs from "tar-fs" import * as tls from "tls" import * as url from "url" import { HttpCode, HttpError } from "../common/http" -import { normalize, plural, split } from "../common/util" +import { normalize, Options, plural, split } from "../common/util" import { SocketProxyProvider } from "./socket" import { getMediaMime, xdgLocalDir } from "./util" @@ -165,14 +165,36 @@ export abstract class HttpProvider { return normalize("./" + (depth > 1 ? "../".repeat(depth - 1) : "")) } + /** + * Get error response. + */ public async getErrorRoot(route: Route, title: string, header: string, body: string): Promise { const response = await this.getUtf8Resource(this.rootPath, "src/browser/pages/error.html") response.content = response.content - .replace(/{{COMMIT}}/g, this.options.commit) - .replace(/{{BASE}}/g, this.base(route)) .replace(/{{ERROR_TITLE}}/g, title) .replace(/{{ERROR_HEADER}}/g, header) .replace(/{{ERROR_BODY}}/g, body) + return this.replaceTemplates(route, response) + } + + /** + * Replace common templates strings. + */ + protected replaceTemplates( + route: Route, + response: HttpStringFileResponse, + sessionId?: string, + ): HttpStringFileResponse { + const options: Options = { + base: this.base(route), + commit: this.options.commit, + logLevel: logger.level, + sessionId, + } + response.content = response.content + .replace(/{{COMMIT}}/g, this.options.commit) + .replace(/{{BASE}}/g, this.base(route)) + .replace(/"{{OPTIONS}}"/, `'${JSON.stringify(options)}'`) return response } @@ -338,11 +360,15 @@ export class Heart { clearTimeout(this.heartbeatTimer) } this.heartbeatTimer = setTimeout(() => { - this.isActive().then((active) => { - if (active) { - this.beat() - } - }) + this.isActive() + .then((active) => { + if (active) { + this.beat() + } + }) + .catch((error) => { + logger.warn(error.message) + }) }, this.heartbeatInterval) } }