Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/frontend/public/worker-proxy.js
2500 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
// @ts-check
8
9
/**
10
* The proxy (shared) worker serving from the workspace origin to fetch content from the blobserve origin.
11
*/
12
13
// TODO(ak) importScripts is not going to work for module workers: https://web.dev/module-workers/
14
(function () {
15
var originalImportScripts = self.importScripts;
16
// hash contains the original worker URL to be used as a base URI to resolve script URLs
17
var baseURI = decodeURI(location.hash.substr(1));
18
19
self.importScripts = function (...scriptUrls) {
20
return originalImportScripts(...scriptUrls.map((scriptUrl) => new URL(scriptUrl, baseURI).toString()));
21
};
22
23
var originalFetch = self.fetch;
24
self.fetch = function (input, init) {
25
if (typeof input === "string") {
26
return originalFetch(new URL(input, baseURI).toString(), init);
27
}
28
return originalFetch(input, init);
29
};
30
31
var originalRequest = self.Request;
32
function RequestProxy(input, init) {
33
if (typeof input === "string") {
34
return new originalRequest(new URL(input, baseURI).toString(), init);
35
}
36
return new originalRequest(input, init);
37
}
38
RequestProxy.prototype = Object.create(originalRequest);
39
self.Request = RequestProxy;
40
41
originalImportScripts(baseURI);
42
})();
43
44