From 41c6b21bd5c987cbb58c1e93f48fc7283469e533 Mon Sep 17 00:00:00 2001 From: Chunwai Li Date: Tue, 3 Oct 2023 19:13:00 -0500 Subject: [PATCH] Modify asset proxy field to accept just host strings --- src/loaders/configure/configure.js | 2 +- src/loaders/configure/public-path.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/loaders/configure/configure.js b/src/loaders/configure/configure.js index 07c4e00af..bbc5dd2fd 100644 --- a/src/loaders/configure/configure.js +++ b/src/loaders/configure/configure.js @@ -33,7 +33,7 @@ export function configure (agentIdentifier, opts = {}, loaderType, forceDrain) { if (!alreadySetOnce) { alreadySetOnce = true if (updatedInit.proxy.assets) { - redefinePublicPath(updatedInit.proxy.assets + '/') // much like the info.beacon & init.proxy.beacon, this input should not end in a slash, but one is needed for webpack concat + redefinePublicPath(updatedInit.proxy.assets) internalTrafficList.push(updatedInit.proxy.assets) } if (updatedInit.proxy.beacon) internalTrafficList.push(updatedInit.proxy.beacon) diff --git a/src/loaders/configure/public-path.js b/src/loaders/configure/public-path.js index 8a8c36bac..9d90281a8 100644 --- a/src/loaders/configure/public-path.js +++ b/src/loaders/configure/public-path.js @@ -1,6 +1,9 @@ // Set the default CDN or remote for fetching the assets; NPM shouldn't change this var. -export const redefinePublicPath = (url) => { - // There's no URL validation here, so caller should check arg if need be. - __webpack_public_path__ = url // eslint-disable-line +export const redefinePublicPath = (urlString) => { + const isOrigin = urlString.startsWith('http') + // Input is not expected to end in a slash, but webpack concats as-is, so one is inserted. + urlString += '/' + // If there's no existing HTTP scheme, the secure protocol is prepended by default. + __webpack_public_path__ = isOrigin ? urlString : 'https://' + urlString // eslint-disable-line }