Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCliftonGuardian committed Dec 20, 2024
1 parent 3d7b8e1 commit c8666cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
10 changes: 5 additions & 5 deletions dotcom-rendering/src/lib/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('decideAssetOrigin for stage', () => {
);
});
it('DEV', () => {
expect(decideAssetOrigin('DEV', true)).toEqual(BASE_URL_DEV);
expect(decideAssetOrigin('dev', true)).toEqual(BASE_URL_DEV);
expect(decideAssetOrigin(undefined, false)).toEqual('/');
expect(decideAssetOrigin('DEV')).toEqual(BASE_URL_DEV);
expect(decideAssetOrigin('dev')).toEqual(BASE_URL_DEV);
expect(decideAssetOrigin(undefined)).toEqual(BASE_URL_DEV);
});
});

Expand Down Expand Up @@ -82,13 +82,13 @@ describe('getPathFromManifest', () => {

it('returns correct hashed asset (1)', () => {
expect(getPathFromManifest('client.web', '7305.client.web.js')).toBe(
'/assets/7305.client.web.8cdc05567d98ebd9f67e.js',
'http://localhost:3030/assets/7305.client.web.8cdc05567d98ebd9f67e.js',
);
});

it('returns correct hashed asset (2)', () => {
expect(getPathFromManifest('client.web', '356.client.web.js')).toBe(
'/assets/356.client.web.0a1bbdf8c7a5e5826b7c.js',
'http://localhost:3030/assets/356.client.web.0a1bbdf8c7a5e5826b7c.js',
);
});

Expand Down
13 changes: 3 additions & 10 deletions dotcom-rendering/src/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,22 @@ export type AssetOrigin =
* Decides the url to use for fetching assets
*
* @param {'PROD' | 'CODE' | undefined} stage the environment code is executing in
* @param {boolean} isDev whether the environment is development
* @returns {AssetOrigin}
*/
export const decideAssetOrigin = (
stage: string | undefined,
isDev?: boolean,
): AssetOrigin => {
if (isDev) {
return BASE_URL_DEV;
}
export const decideAssetOrigin = (stage: string | undefined): AssetOrigin => {
switch (stage?.toUpperCase()) {
case 'PROD':
return 'https://assets.guim.co.uk/';
case 'CODE':
return 'https://assets-code.guim.co.uk/';
default:
return '/';
return BASE_URL_DEV;
}
};

const isDev = process.env.NODE_ENV === 'development';

export const ASSET_ORIGIN = decideAssetOrigin(process.env.GU_STAGE, isDev);
export const ASSET_ORIGIN = decideAssetOrigin(process.env.GU_STAGE);

const isAssetHash = (manifest: unknown): manifest is AssetHash =>
isObject(manifest) &&
Expand Down

0 comments on commit c8666cd

Please sign in to comment.