Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-154] Rename manifest filename #8

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The main entry point is [src/service-worker/main.ts](src/service-worker/main.ts)
```
├── src
│   ├── landing-page - splash screen displayed to users when making request to domain node, initializing service worker and fetching content from content nodes
│   │   └── armada
│   │   └── earthfast
│   │   ├── fonts
│   │   ├── images
│   │   └── styles
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/manifest-failure.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ it('manifest fetch on content nodes failure', () => {
harness.intercept();
harness.spyOnMessages(window);

content0.failResource('earthfast.json');
content0.failResource('armada.json');

cy.visit(harness.domainNode.url);
Expand Down
35 changes: 21 additions & 14 deletions src/service-worker/src/armada/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const IDLE_DELAY = 1000;
const MAX_IDLE_DELAY = 5000;

export class ArmadaDriver extends Driver {
public static readonly MANIFEST_FILENAME = 'armada.json';
public static readonly MANIFEST_FILENAME = 'earthfast.json';
public static readonly FALLBACK_MANIFEST_FILENAME = 'armada.json';

// Override the state property so we can panic if the service worker ever attempts to transition
// into a non-NORMAL state. We throw an error instead of just ignoring it because such a
Expand Down Expand Up @@ -203,22 +204,28 @@ export class ArmadaDriver extends Driver {
}

protected async fetchLatestManifestOnce(node: string): Promise<string> {
let resp: Response;
try {
resp = await this.apiClient.getContent(ArmadaDriver.MANIFEST_FILENAME, node);
} catch (err) {
const msg = `Error fetching manifest: node=${node} error=${err}`;
await this.broadcast(MsgManifestFetchError(msg));
throw err;
}
const filenames = [ArmadaDriver.MANIFEST_FILENAME, ArmadaDriver.FALLBACK_MANIFEST_FILENAME];
for (const filename of filenames) {
try {
const resp = await this.apiClient.getContent(filename, node);

if (!resp.ok) {
const msg = `Error fetching manifest: node=${node} status=${resp.status}`;
await this.broadcast(MsgManifestFetchError(msg));
throw new SwManifestFetchFailureError(msg);
if (resp.ok) {
return resp.text();
}

if (filename === filenames[filenames.length - 1]) {
throw new Error(`HTTP error: ${resp.status}`);
}
} catch (err) {
if (filename === filenames[filenames.length - 1]) {
const msg = `Error fetching manifest: node=${node} error=${err}`;
await this.broadcast(MsgManifestFetchError(msg));
throw new SwManifestFetchFailureError(msg);
}
}
}

return resp.text();
throw new Error('Unexpected error in fetchLatestManifestOnce');
}

protected async probeLatestManifest(): Promise<Manifest> {
Expand Down
Loading