From d47591e253bfbc30d3c70b6eb080984aa0e882a3 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 18 Feb 2020 12:57:45 -0600 Subject: [PATCH] Inject base path into manifest Might fix #1181, although not for the reasons I initially thought (because the URLs are resolved from the manifest path, not the path of the current page). This should ensure that the URLs used by the manifest are always correct regardless of the manifest's path. --- src/browser/media/manifest.json | 4 ++-- src/node/app/app.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/browser/media/manifest.json b/src/browser/media/manifest.json index 513304e1..0b9a7e1d 100644 --- a/src/browser/media/manifest.json +++ b/src/browser/media/manifest.json @@ -1,12 +1,12 @@ { "name": "code-server", "short_name": "code-server", - "start_url": "../../../..", + "start_url": "{{BASE}}", "display": "fullscreen", "background-color": "#fff", "description": "Run editors on a remote server.", "icons": [{ - "src": "./code-server.png", + "src": "{{BASE}}/static-{{COMMIT}}/src/browser/media/code-server.png", "sizes": "384x384", "type": "image/png" }] diff --git a/src/node/app/app.ts b/src/node/app/app.ts index c80fb0b7..8c65e0f7 100644 --- a/src/node/app/app.ts +++ b/src/node/app/app.ts @@ -24,7 +24,7 @@ export class MainHttpProvider extends HttpProvider { switch (route.base) { case "/static": { this.ensureMethod(request) - const response = await this.getResource(this.rootPath, route.requestPath) + const response = await this.getReplacedResource(route) if (!this.isDev) { response.cache = true } @@ -75,6 +75,20 @@ export class MainHttpProvider extends HttpProvider { return this.getErrorRoot(route, "404", "404", "Application not found") } + /** + * Return a resource with variables replaced where necessary. + */ + protected async getReplacedResource(route: Route): Promise { + if (route.requestPath.endsWith("/manifest.json")) { + const response = await this.getUtf8Resource(this.rootPath, route.requestPath) + response.content = response.content + .replace(/{{BASE}}/g, this.base(route)) + .replace(/{{COMMIT}}/g, this.options.commit) + return response + } + return this.getResource(this.rootPath, route.requestPath) + } + public async getRoot(route: Route): Promise { const recent = await this.api.recent() const apps = await this.api.installedApplications()