From f93421086669180817005acf45dc70fc7794ec1b Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:19:57 +0000 Subject: [PATCH 1/5] Use full base url --- dotcom-rendering/src/client/decidePublicPath.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotcom-rendering/src/client/decidePublicPath.ts b/dotcom-rendering/src/client/decidePublicPath.ts index 41bb44db145..4ccf9549402 100644 --- a/dotcom-rendering/src/client/decidePublicPath.ts +++ b/dotcom-rendering/src/client/decidePublicPath.ts @@ -8,6 +8,6 @@ export const decidePublicPath = (): string => { const isLocalHost = window.location.hostname === 'localhost'; // Use relative path if running locally or in CI return isDev || isLocalHost - ? '/assets/' + ? 'http://localhost:3030/assets/' : `${window.guardian.config.frontendAssetsFullURL}assets/`; }; From c281dad074b217ddf8825d4ab37de4d74016e168 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:32:09 +0000 Subject: [PATCH 2/5] Update decidePublicPath.ts --- dotcom-rendering/src/client/decidePublicPath.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dotcom-rendering/src/client/decidePublicPath.ts b/dotcom-rendering/src/client/decidePublicPath.ts index 4ccf9549402..96f1ab3af9e 100644 --- a/dotcom-rendering/src/client/decidePublicPath.ts +++ b/dotcom-rendering/src/client/decidePublicPath.ts @@ -6,8 +6,14 @@ export const decidePublicPath = (): string => { const isDev = process.env.NODE_ENV === 'development'; const isLocalHost = window.location.hostname === 'localhost'; - // Use relative path if running locally or in CI - return isDev || isLocalHost - ? 'http://localhost:3030/assets/' - : `${window.guardian.config.frontendAssetsFullURL}assets/`; + + if (isLocalHost) { + return 'http://localhost:3030/assets/'; + } + + if (isDev) { + return '/assets/'; + } + + return `${window.guardian.config.frontendAssetsFullURL}assets/`; }; From a5302f1b91bcd8a240e317a5dec7c4af0dadebd1 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:39:31 +0000 Subject: [PATCH 3/5] Update decidePublicPath.test.ts --- dotcom-rendering/src/client/decidePublicPath.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotcom-rendering/src/client/decidePublicPath.test.ts b/dotcom-rendering/src/client/decidePublicPath.test.ts index 85ebbf20e3c..3a8efbbe5fd 100644 --- a/dotcom-rendering/src/client/decidePublicPath.test.ts +++ b/dotcom-rendering/src/client/decidePublicPath.test.ts @@ -44,7 +44,7 @@ describe('decidePublicPath', () => { it('with production flag and localhost', () => { process.env.NODE_ENV = 'production'; mockHostname('localhost'); - expect(decidePublicPath()).toEqual('/assets/'); + expect(decidePublicPath()).toEqual('http://localhost:3030/assets/'); }); it('with no flag', () => { From 915c73adb9fe7fb031ee3d84e3b86473b44c3fd9 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:45:14 +0000 Subject: [PATCH 4/5] Playwright --- dotcom-rendering/playwright.config.ts | 3 +++ dotcom-rendering/src/client/decidePublicPath.ts | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dotcom-rendering/playwright.config.ts b/dotcom-rendering/playwright.config.ts index 6ee1a0b70bb..066a72d17dd 100644 --- a/dotcom-rendering/playwright.config.ts +++ b/dotcom-rendering/playwright.config.ts @@ -45,5 +45,8 @@ export default defineConfig({ reuseExistingServer: true, stdout: 'pipe', stderr: 'pipe', + env: { + PLAYWRIGHT: 'true', + }, }, }); diff --git a/dotcom-rendering/src/client/decidePublicPath.ts b/dotcom-rendering/src/client/decidePublicPath.ts index 96f1ab3af9e..6c5c145a7e9 100644 --- a/dotcom-rendering/src/client/decidePublicPath.ts +++ b/dotcom-rendering/src/client/decidePublicPath.ts @@ -6,13 +6,14 @@ export const decidePublicPath = (): string => { const isDev = process.env.NODE_ENV === 'development'; const isLocalHost = window.location.hostname === 'localhost'; + const isPlaywright = process.env.PLAYWRIGHT === 'true'; - if (isLocalHost) { - return 'http://localhost:3030/assets/'; + if (isPlaywright) { + return `/assets/`; } - if (isDev) { - return '/assets/'; + if (isDev || isLocalHost) { + return `http://localhost:3030/assets/`; } return `${window.guardian.config.frontendAssetsFullURL}assets/`; From 9f8b024767d861d4a1c414d189340ceca03d7bc5 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:03:32 +0000 Subject: [PATCH 5/5] Update decidePublicPath.ts --- dotcom-rendering/src/client/decidePublicPath.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotcom-rendering/src/client/decidePublicPath.ts b/dotcom-rendering/src/client/decidePublicPath.ts index 6c5c145a7e9..a723d648ed2 100644 --- a/dotcom-rendering/src/client/decidePublicPath.ts +++ b/dotcom-rendering/src/client/decidePublicPath.ts @@ -8,7 +8,7 @@ export const decidePublicPath = (): string => { const isLocalHost = window.location.hostname === 'localhost'; const isPlaywright = process.env.PLAYWRIGHT === 'true'; - if (isPlaywright) { + if (isPlaywright && isDev) { return `/assets/`; }