Fix service worker scope when there is a base path
This commit is contained in:
parent
7389d9e2cb
commit
b566b66590
@ -110,9 +110,8 @@ directory.
|
||||
Our changes include:
|
||||
- Add a `code-server` schema.
|
||||
- Allow multiple extension directories (both user and built-in).
|
||||
- Rewrite assets requested by the browser to use the base URL.
|
||||
- Modify the loader, websocket, webview, and service worker to use the URL of
|
||||
the page as a base (and TLS if necessary for the websocket).
|
||||
- Modify the loader, websocket, webview, service worker, and asset requests to
|
||||
use the URL of the page as a base (and TLS if necessary for the websocket).
|
||||
- Send client-side telemetry through the server.
|
||||
- Add a file prefix to ignore for temporary files created during upload.
|
||||
- Insert our upload service for use in editor windows and explorer.
|
||||
|
@ -60,7 +60,7 @@ index 99bd930a91..319c4bd3c3 100644
|
||||
];
|
||||
|
||||
diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts
|
||||
index fa12f62900..1dbaac1640 100644
|
||||
index fa12f62900..a4c72fee8e 100644
|
||||
--- a/src/vs/base/browser/dom.ts
|
||||
+++ b/src/vs/base/browser/dom.ts
|
||||
@@ -1187,6 +1187,7 @@ export function animate(fn: () => void): IDisposable {
|
||||
@ -80,7 +80,7 @@ index fa12f62900..1dbaac1640 100644
|
||||
// rewrite vscode-remote-uris to uris of the window location
|
||||
// so that they can be intercepted by the service worker
|
||||
- return _location.with({ path: '/vscode-resources/fetch', query: `u=${JSON.stringify(uri)}` });
|
||||
+ return _location.with({ path: `${basePath}/vscode-resources/${uri.fsPath}` });
|
||||
+ return _location.with({ path: `${basePath}/vscode-resources/fetch`, query: `u=${JSON.stringify(uri)}` });
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
@ -715,6 +715,33 @@ index 9235c739fb..32d203eb32 100644
|
||||
this._register(logService.onDidChangeLogLevel(level => logLevelClient.setLevel(level)));
|
||||
}
|
||||
}
|
||||
diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts
|
||||
index 622bb7889b..66dd4b0bbc 100644
|
||||
--- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts
|
||||
+++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts
|
||||
@@ -36,7 +36,8 @@ self.addEventListener('activate', event => {
|
||||
//#region --- fetching/caching
|
||||
|
||||
const _cacheName = 'vscode-resources';
|
||||
-const _resourcePrefix = '/vscode-resources/fetch';
|
||||
+const rootPath = self.location.pathname.replace(/\/out\/vs\/workbench\/contrib\/resources\/browser\/resourceServiceWorkerMain.js$/, '');
|
||||
+const _resourcePrefix = `${rootPath}/vscode-resources/fetch`;
|
||||
const _pendingFetch = new Map<string, Function>();
|
||||
|
||||
self.addEventListener('message', event => {
|
||||
diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
|
||||
index dfda6a1cfb..44a01fb0fb 100644
|
||||
--- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
|
||||
+++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
|
||||
@@ -24,7 +24,7 @@ const _serviceWorker = new class ServiceWorkerStarter {
|
||||
private _messageHandler?: (event: ExtendableMessageEvent) => void;
|
||||
|
||||
constructor() {
|
||||
- navigator.serviceWorker.register(ServiceWorkerStarter._url, { scope: '/' }).then(reg => {
|
||||
+ navigator.serviceWorker.register(ServiceWorkerStarter._url, { scope: window.location.pathname.replace(/\/+$/, '') }).then(reg => {
|
||||
// console.debug('SW#reg', reg);
|
||||
return reg.update();
|
||||
// }).then(() => {
|
||||
diff --git a/src/vs/workbench/contrib/update/electron-browser/update.contribution.ts b/src/vs/workbench/contrib/update/electron-browser/update.contribution.ts
|
||||
index e39fa57979..3c775c9a06 100644
|
||||
--- a/src/vs/workbench/contrib/update/electron-browser/update.contribution.ts
|
||||
|
@ -198,7 +198,7 @@ export abstract class Server {
|
||||
response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
|
||||
"Content-Type": getMediaMime(payload.filePath),
|
||||
...(payload.redirect ? { Location: this.withBase(request, payload.redirect) } : {}),
|
||||
...(request.headers["service-worker"] ? { "Service-Worker-Allowed": this.options.basePath + "/" } : {}),
|
||||
...(request.headers["service-worker"] ? { "Service-Worker-Allowed": this.options.basePath || "/" } : {}),
|
||||
...payload.headers,
|
||||
});
|
||||
response.end(payload.content);
|
||||
@ -442,7 +442,20 @@ export class MainServer extends Server {
|
||||
): Promise<Response> {
|
||||
switch (base) {
|
||||
case "/": return this.getRoot(request, parsedUrl);
|
||||
case "/vscode-resources": return this.getResource(requestPath);
|
||||
case "/vscode-resources":
|
||||
if (requestPath === "/fetch") {
|
||||
// For some reason VS Code encodes the = so the query doesn't parse
|
||||
// correctly. We'll look through what's available and try to find it.
|
||||
for (let value in parsedUrl.query) {
|
||||
if (value && typeof value === "string") {
|
||||
const query = querystring.parse(value);
|
||||
if (typeof query.u === "string") {
|
||||
return this.getResource(JSON.parse(query.u).path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new HttpError("Not found", HttpCode.NotFound);
|
||||
case "/webview":
|
||||
if (requestPath.indexOf("/vscode-resource") === 0) {
|
||||
return this.getResource(requestPath.replace(/^\/vscode-resource/, ""));
|
||||
|
Loading…
Reference in New Issue
Block a user