From a68c28e70f2fb3847d367b333a5c4aa5db5672c0 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Wed, 16 Feb 2022 15:01:53 -0500 Subject: [PATCH 1/2] Fix local assets path and upload proxy for localhost --- src/utils/configs.js | 11 +++++++++-- webpack.config.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/configs.js b/src/utils/configs.js index eb8c96d3ca..ff9ba1a9c3 100644 --- a/src/utils/configs.js +++ b/src/utils/configs.js @@ -22,9 +22,16 @@ let isAdmin = false; const el = document.querySelector(`meta[name='env:${x.toLowerCase()}']`); configs[x] = el ? el.getAttribute("content") : process.env[x]; - if (x === "BASE_ASSETS_PATH" && configs[x]) { + if (x === "BASE_ASSETS_PATH" && configs["BASE_ASSETS_PATH"]) { // eslint-disable-next-line no-undef - __webpack_public_path__ = configs[x]; + __webpack_public_path__ = configs["BASE_ASSETS_PATH"]; + + // BASE_ASSETS_PATH might be a relative URL like "/" when it is set in + // .env or .defaults.env when running locally. We need to convert that + // to an absolute URL. + if (configs["BASE_ASSETS_PATH"] && !configs["BASE_ASSETS_PATH"].startsWith("http")) { + configs["BASE_ASSETS_PATH"] = new URL(configs["BASE_ASSETS_PATH"], window.location); + } } }); diff --git a/webpack.config.js b/webpack.config.js index acc114db1d..e77c8a6409 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -322,7 +322,7 @@ module.exports = async (env, argv) => { if (req.method === "OPTIONS") { res.send(); } else { - const url = req.path.replace("/cors-proxy/", ""); + const url = req.originalUrl.replace("/cors-proxy/", ""); request({ url, method: req.method }, error => { if (error) { console.error(`cors-proxy: error fetching "${url}"\n`, error); From f35028a77f7062f254675482212c58ad2d9922b6 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Wed, 16 Feb 2022 18:23:48 -0500 Subject: [PATCH 2/2] PR feedback --- src/utils/configs.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/utils/configs.js b/src/utils/configs.js index ff9ba1a9c3..cec4bf3572 100644 --- a/src/utils/configs.js +++ b/src/utils/configs.js @@ -22,16 +22,17 @@ let isAdmin = false; const el = document.querySelector(`meta[name='env:${x.toLowerCase()}']`); configs[x] = el ? el.getAttribute("content") : process.env[x]; - if (x === "BASE_ASSETS_PATH" && configs["BASE_ASSETS_PATH"]) { - // eslint-disable-next-line no-undef - __webpack_public_path__ = configs["BASE_ASSETS_PATH"]; - + const BASE_ASSETS_PATH_KEY = "BASE_ASSETS_PATH"; + if (x === BASE_ASSETS_PATH_KEY && configs[BASE_ASSETS_PATH_KEY]) { // BASE_ASSETS_PATH might be a relative URL like "/" when it is set in // .env or .defaults.env when running locally. We need to convert that // to an absolute URL. - if (configs["BASE_ASSETS_PATH"] && !configs["BASE_ASSETS_PATH"].startsWith("http")) { - configs["BASE_ASSETS_PATH"] = new URL(configs["BASE_ASSETS_PATH"], window.location); + if (!configs[BASE_ASSETS_PATH_KEY].startsWith("http")) { + configs[BASE_ASSETS_PATH_KEY] = new URL(configs[BASE_ASSETS_PATH_KEY], window.location).toString(); } + + // eslint-disable-next-line no-undef + __webpack_public_path__ = configs[BASE_ASSETS_PATH_KEY]; } });