fix(service-worker): use relative path for ngsw.json
Not every application is served from the domain root. The Service Worker made a bad assumption that it would be, and so requested /ngsw.json from the domain root. This change corrects this assumption, and requests ngsw.json without the leading slash. This causes the request to be interpreted relative to the SW origin, which will be the application root.
This commit is contained in:
parent
3fbcde9048
commit
f582620d5b
|
@ -580,8 +580,8 @@ export class Driver implements Debuggable, UpdateSource {
|
|||
* Retrieve a copy of the latest manifest from the server.
|
||||
*/
|
||||
private async fetchLatestManifest(): Promise<Manifest> {
|
||||
const res = await this.safeFetch(
|
||||
this.adapter.newRequest('/ngsw.json?ngsw-cache-bust=' + Math.random()));
|
||||
const res =
|
||||
await this.safeFetch(this.adapter.newRequest('ngsw.json?ngsw-cache-bust=' + Math.random()));
|
||||
if (!res.ok) {
|
||||
if (res.status === 404) {
|
||||
await this.deleteAllCaches();
|
||||
|
|
|
@ -158,7 +158,7 @@ export function main() {
|
|||
expect(await scope.startup(true)).toEqual(true);
|
||||
await scope.resolveSelfMessages();
|
||||
await driver.initialized;
|
||||
server.assertSawRequestFor('/ngsw.json');
|
||||
server.assertSawRequestFor('ngsw.json');
|
||||
server.assertSawRequestFor('/foo.txt');
|
||||
server.assertSawRequestFor('/bar.txt');
|
||||
server.assertSawRequestFor('/redirected.txt');
|
||||
|
@ -170,7 +170,7 @@ export function main() {
|
|||
async_it('initializes prefetched content correctly, after a request kicks it off', async() => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
await driver.initialized;
|
||||
server.assertSawRequestFor('/ngsw.json');
|
||||
server.assertSawRequestFor('ngsw.json');
|
||||
server.assertSawRequestFor('/foo.txt');
|
||||
server.assertSawRequestFor('/bar.txt');
|
||||
server.assertSawRequestFor('/redirected.txt');
|
||||
|
@ -230,7 +230,7 @@ export function main() {
|
|||
|
||||
scope.updateServerState(serverUpdate);
|
||||
expect(await driver.checkForUpdate()).toEqual(true);
|
||||
serverUpdate.assertSawRequestFor('/ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('/foo.txt');
|
||||
serverUpdate.assertSawRequestFor('/redirected.txt');
|
||||
serverUpdate.assertNoOtherRequests();
|
||||
|
@ -263,7 +263,7 @@ export function main() {
|
|||
|
||||
scope.updateServerState(serverUpdate);
|
||||
expect(await driver.checkForUpdate()).toEqual(true);
|
||||
serverUpdate.assertSawRequestFor('/ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('/foo.txt');
|
||||
serverUpdate.assertSawRequestFor('/redirected.txt');
|
||||
serverUpdate.assertNoOtherRequests();
|
||||
|
@ -331,7 +331,7 @@ export function main() {
|
|||
scope.advance(12000);
|
||||
await driver.idle.empty;
|
||||
|
||||
serverUpdate.assertSawRequestFor('/ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('ngsw.json');
|
||||
serverUpdate.assertSawRequestFor('/foo.txt');
|
||||
serverUpdate.assertSawRequestFor('/redirected.txt');
|
||||
serverUpdate.assertNoOtherRequests();
|
||||
|
|
|
@ -73,7 +73,7 @@ export class MockServerStateBuilder {
|
|||
}
|
||||
|
||||
withManifest(manifest: Manifest): MockServerStateBuilder {
|
||||
this.resources.set('/ngsw.json', new MockResponse(JSON.stringify(manifest)));
|
||||
this.resources.set('ngsw.json', new MockResponse(JSON.stringify(manifest)));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue