refactor(service-worker): use Adapter#parseUrl()
for all URL parsing (#27080)
This commit also ensures that the correct implementation is used on environments that do not support `URL` (e.g. Node.js). PR Close #27080
This commit is contained in:
parent
a24f4b51b3
commit
6cd3743b44
@ -18,7 +18,7 @@ export class Adapter {
|
|||||||
constructor(scope: ServiceWorkerGlobalScope) {
|
constructor(scope: ServiceWorkerGlobalScope) {
|
||||||
// Suffixing `ngsw` with the baseHref to avoid clash of cache names
|
// Suffixing `ngsw` with the baseHref to avoid clash of cache names
|
||||||
// for SWs with different scopes on the same domain.
|
// for SWs with different scopes on the same domain.
|
||||||
const baseHref = new URL(scope.registration.scope).pathname;
|
const baseHref = this.parseUrl(scope.registration.scope).path;
|
||||||
this.cacheNamePrefix = 'ngsw:' + baseHref;
|
this.cacheNamePrefix = 'ngsw:' + baseHref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,9 +116,9 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private server: MockServerState, readonly caches: MockCacheStorage, private origin: string) {
|
private server: MockServerState, readonly caches: MockCacheStorage, private origin: string) {
|
||||||
this.time = Date.now();
|
const baseHref = this.parseUrl(origin).path;
|
||||||
const baseHref = new URL(this.registration.scope).pathname;
|
|
||||||
this.cacheNamePrefix = 'ngsw:' + baseHref;
|
this.cacheNamePrefix = 'ngsw:' + baseHref;
|
||||||
|
this.time = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveSelfMessages(): Promise<void> {
|
async resolveSelfMessages(): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user