Skip to content

Commit

Permalink
fix/asset-url-path
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCliftonGuardian committed Dec 19, 2024
1 parent b834ecf commit bc62af9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions dotcom-rendering/src/lib/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';
import { BUILD_VARIANT } from '../../webpack/bundles';
import {
APPS_SCRIPT,
BASE_URL_DEV,
decideAssetOrigin,
getModulesBuild,
getPathFromManifest,
Expand All @@ -27,9 +28,9 @@ describe('decideAssetOrigin for stage', () => {
);
});
it('DEV', () => {
expect(decideAssetOrigin('DEV')).toEqual('/');
expect(decideAssetOrigin('dev')).toEqual('/');
expect(decideAssetOrigin(undefined)).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 @@ -81,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
6 changes: 4 additions & 2 deletions dotcom-rendering/src/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ interface AssetHash {
[key: string]: string;
}

export const BASE_URL_DEV = 'http://localhost:3030/';

export type AssetOrigin =
| 'https://assets.guim.co.uk/'
| 'https://assets-code.guim.co.uk/'
| '/';
| typeof BASE_URL_DEV;

/**
* Decides the url to use for fetching assets
Expand All @@ -27,7 +29,7 @@ export const decideAssetOrigin = (stage: string | undefined): AssetOrigin => {
case 'CODE':
return 'https://assets-code.guim.co.uk/';
default:
return '/';
return BASE_URL_DEV;
}
};

Expand Down

0 comments on commit bc62af9

Please sign in to comment.