[web] Fix paths fetched by flutter.js (#118684)

This commit is contained in:
Mouad Debbar
2023-01-23 10:02:58 -05:00
committed by GitHub
parent bd7bee0f9e
commit 3bf79607dd
2 changed files with 29 additions and 3 deletions

View File

@@ -20,6 +20,21 @@ _flutter.loader = null;
(function () {
"use strict";
const baseUri = ensureTrailingSlash(getBaseURI());
function getBaseURI() {
const base = document.querySelector("base");
return (base && base.getAttribute("href")) || "";
}
function ensureTrailingSlash(uri) {
if (uri == "") {
return uri;
}
return uri.endsWith("/") ? uri : `${uri}/`;
}
/**
* Wraps `promise` in a timeout of the given `duration` in ms.
*
@@ -120,8 +135,7 @@ _flutter.loader = null;
}
const {
serviceWorkerVersion,
serviceWorkerUrl = "flutter_service_worker.js?v=" +
serviceWorkerVersion,
serviceWorkerUrl = `${baseUri}flutter_service_worker.js?v=${serviceWorkerVersion}`,
timeoutMillis = 4000,
} = settings;
@@ -239,7 +253,7 @@ _flutter.loader = null;
* Returns undefined when an `onEntrypointLoaded` callback is supplied in `options`.
*/
async loadEntrypoint(options) {
const { entrypointUrl = "main.dart.js", onEntrypointLoaded } =
const { entrypointUrl = `${baseUri}main.dart.js`, onEntrypointLoaded } =
options || {};
return this._loadEntrypoint(entrypointUrl, onEntrypointLoaded);