Skip to content

Commit d47591e

Browse files
committed
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.
1 parent 39a5770 commit d47591e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/browser/media/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "code-server",
33
"short_name": "code-server",
4-
"start_url": "../../../..",
4+
"start_url": "{{BASE}}",
55
"display": "fullscreen",
66
"background-color": "#fff",
77
"description": "Run editors on a remote server.",
88
"icons": [{
9-
"src": "./code-server.png",
9+
"src": "{{BASE}}/static-{{COMMIT}}/src/browser/media/code-server.png",
1010
"sizes": "384x384",
1111
"type": "image/png"
1212
}]

src/node/app/app.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class MainHttpProvider extends HttpProvider {
2424
switch (route.base) {
2525
case "/static": {
2626
this.ensureMethod(request)
27-
const response = await this.getResource(this.rootPath, route.requestPath)
27+
const response = await this.getReplacedResource(route)
2828
if (!this.isDev) {
2929
response.cache = true
3030
}
@@ -75,6 +75,20 @@ export class MainHttpProvider extends HttpProvider {
7575
return this.getErrorRoot(route, "404", "404", "Application not found")
7676
}
7777

78+
/**
79+
* Return a resource with variables replaced where necessary.
80+
*/
81+
protected async getReplacedResource(route: Route): Promise<HttpResponse> {
82+
if (route.requestPath.endsWith("/manifest.json")) {
83+
const response = await this.getUtf8Resource(this.rootPath, route.requestPath)
84+
response.content = response.content
85+
.replace(/{{BASE}}/g, this.base(route))
86+
.replace(/{{COMMIT}}/g, this.options.commit)
87+
return response
88+
}
89+
return this.getResource(this.rootPath, route.requestPath)
90+
}
91+
7892
public async getRoot(route: Route): Promise<HttpResponse> {
7993
const recent = await this.api.recent()
8094
const apps = await this.api.installedApplications()

0 commit comments

Comments
 (0)