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.
This commit is contained in:
parent
39a57700bc
commit
d47591e253
|
@ -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"
|
||||
}]
|
||||
|
|
|
@ -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<HttpResponse> {
|
||||
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<HttpResponse> {
|
||||
const recent = await this.api.recent()
|
||||
const apps = await this.api.installedApplications()
|
||||
|
|
Loading…
Reference in New Issue