Skip to content
Open
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
6 changes: 4 additions & 2 deletions dotcom-rendering/src/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const decideAssetOrigin = (
const isDev = process.env.NODE_ENV === 'development';

export const ASSET_ORIGIN = decideAssetOrigin(process.env.GU_STAGE, isDev);
export const ASSET_ORIGIN_APPS: AssetOrigin = isDev ? '/' : ASSET_ORIGIN;

const isAssetHash = (manifest: unknown): manifest is AssetHash =>
isObject(manifest) &&
Expand Down Expand Up @@ -82,13 +83,14 @@ const getManifestPath = (build: Build): ManifestPath =>
export const getPathFromManifest = (
build: Build,
filename: `${string}.js`,
assetOrigin: AssetOrigin = ASSET_ORIGIN,
): string => {
if (!filename.endsWith('.js')) {
throw new Error('Invalid filename: extension must be .js');
}

if (isDev) {
return `${ASSET_ORIGIN}assets/${filename.replace(
return `${assetOrigin}assets/${filename.replace(
'.js',
`.${build}.js`,
)}`;
Expand All @@ -101,7 +103,7 @@ export const getPathFromManifest = (
throw new Error(`Missing manifest for ${filename}`);
}

return `${ASSET_ORIGIN}assets/${filenameFromManifest}`;
return `${assetOrigin}assets/${filenameFromManifest}`;
};

/**
Expand Down
10 changes: 5 additions & 5 deletions dotcom-rendering/src/server/render.article.apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getArticleThemeString,
} from '../lib/articleFormat';
import {
ASSET_ORIGIN,
ASSET_ORIGIN_APPS,
generateScriptTags,
getPathFromManifest,
} from '../lib/assets';
Expand All @@ -33,7 +33,7 @@ export const renderArticle = (
const config: Config = {
renderingTarget,
darkModeAvailable: true,
assetOrigin: ASSET_ORIGIN,
assetOrigin: ASSET_ORIGIN_APPS,
editionId: frontendData.editionId,
};

Expand Down Expand Up @@ -62,9 +62,9 @@ export const renderArticle = (
);

const clientScripts = [
getPathFromManifest('client.apps', 'index.js'),
getPathFromManifest('client.apps', 'index.js', ASSET_ORIGIN_APPS),
pageHasNonBootInteractiveElements &&
`${ASSET_ORIGIN}static/frontend/js/curl-with-js-and-domReady.js`,
`${ASSET_ORIGIN_APPS}static/frontend/js/curl-with-js-and-domReady.js`,
].filter(isString);
const scriptTags = generateScriptTags([...clientScripts]);

Expand Down Expand Up @@ -167,7 +167,7 @@ export const renderAppsBlocks = ({
const config: Config = {
renderingTarget: 'Apps',
darkModeAvailable: true,
assetOrigin: ASSET_ORIGIN,
assetOrigin: ASSET_ORIGIN_APPS,
editionId,
};

Expand Down
6 changes: 3 additions & 3 deletions dotcom-rendering/src/server/render.sportDataPage.app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isString } from '@guardian/libs';
import { ConfigProvider } from '../components/ConfigContext';
import { SportDataPageComponent } from '../components/SportDataPageComponent';
import {
ASSET_ORIGIN,
ASSET_ORIGIN_APPS,
generateScriptTags,
getPathFromManifest,
} from '../lib/assets';
Expand All @@ -19,7 +19,7 @@ export const renderAppsSportPage = (sportData: FootballMatchInfoPage) => {
const config: Config = {
renderingTarget,
darkModeAvailable: true,
assetOrigin: ASSET_ORIGIN,
assetOrigin: ASSET_ORIGIN_APPS,
editionId: sportData.editionId,
};

Expand All @@ -36,7 +36,7 @@ export const renderAppsSportPage = (sportData: FootballMatchInfoPage) => {
);

const clientScripts = [
getPathFromManifest('client.apps', 'index.js'),
getPathFromManifest('client.apps', 'index.js', ASSET_ORIGIN_APPS),
].filter(isString);
const scriptTags = generateScriptTags([...clientScripts]);

Expand Down
Loading