Skip to content

Commit

Permalink
User only has to specify host, not entire origin
Browse files Browse the repository at this point in the history
  • Loading branch information
skitterm committed Nov 16, 2023
1 parent 88a0f67 commit 2a264ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/resource-archive/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ describe('new', () => {
const complete = await createResourceArchive({
page,
allowedArchiveDomains: [
// external origins we allow-list
'https://i-ama.fake',
'https://another-domain.com',
// external domains we allow-list
'i-ama.fake',
'another-domain.com',
],
});

Expand Down
7 changes: 4 additions & 3 deletions src/resource-archive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Watcher {
Specifies which domains (origins) we should archive resources for (by default we only archive same-origin resources).
Useful in situations where the environment running the archived storybook (e.g. in CI) may be restricted to an intranet or other domain restrictions
*/
private allowedArchiveDomains: string[];
private allowedArchiveOrigins: string[];

/**
* We assume the first URL loaded after @watch is called is the base URL of the
Expand All @@ -51,7 +51,8 @@ class Watcher {
allowedDomains?: string[]
) {
this.globalNetworkTimeoutMs = networkTimeoutMs;
this.allowedArchiveDomains = allowedDomains || [];
// tack on the protocol so we can properly check if requests are cross-origin
this.allowedArchiveOrigins = (allowedDomains || []).map((domain) => `https://${domain}`);
}

async watch() {
Expand Down Expand Up @@ -141,7 +142,7 @@ class Watcher {

const isRequestFromAllowedDomain =
requestUrl.origin === this.firstUrl.origin ||
this.allowedArchiveDomains.includes(requestUrl.origin);
this.allowedArchiveOrigins.includes(requestUrl.origin);

logger.log(
'requestPaused',
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export interface ChromaticConfig {
// each test will wait for the network to be idle while archiving resources.
resourceArchiveTimeout?: number;

// domains (besides localhost) that assets should be archived from
// domains (besides where the test is being run from) that assets should be archived from
// (needed when, for example, CI environment can't access the archives later on)
// ex: https://www.some-domain.com
// ex: www.some-domain.com
allowedArchiveDomains?: string[];
}

Expand Down

0 comments on commit 2a264ca

Please sign in to comment.