From 67fceb0ce91b3017bf237bce7a1876ae60d775a6 Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Fri, 1 Nov 2024 20:13:57 +0100 Subject: [PATCH] fix missing basePath --- CHANGELOG.md | 1 + js/loader.js | 2 +- js/main.js | 2 +- modules/default/newsfeed/newsfeed.js | 2 +- modules/default/utils.js | 10 ++++++---- modules/default/weather/weatherprovider.js | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3158a93016..1ccf50e600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ _This release is scheduled to be released on 2025-01-01._ - [weather] changed default value for weatherEndpoint of provider openweathermap to "/onecall" (#3574) - [tests] fix electron tests with mock dates, the mock on server side was missing (#3597) - [tests] fix testcases with hard coded Date.now (#3597) +- [core] Fix missing `basePath` where `location.host` is used (#3613) ## [2.29.0] - 2024-10-01 diff --git a/js/loader.js b/js/loader.js index 9b42dd8493..e823b0b620 100644 --- a/js/loader.js +++ b/js/loader.js @@ -15,7 +15,7 @@ const Loader = (function () { * @returns {object} with key: values as assembled in js/server_functions.js */ const getEnvVars = async function () { - const res = await fetch(`${location.protocol}//${location.host}/env`); + const res = await fetch(`${location.protocol}//${location.host}${config.basePath}env`); return JSON.parse(await res.text()); }; diff --git a/js/main.js b/js/main.js index 16aaa1b1b4..7c0e9db390 100644 --- a/js/main.js +++ b/js/main.js @@ -608,7 +608,7 @@ const MM = (function () { // if server startup time has changed (which means server was restarted) // the client reloads the mm page try { - const res = await fetch(`${location.protocol}//${location.host}/startup`); + const res = await fetch(`${location.protocol}//${location.host}${config.basePath}startup`); const curr = await res.text(); if (startUp === "") startUp = curr; if (startUp !== curr) { diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index c66f8990d8..95c4cde91e 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -38,7 +38,7 @@ Module.register("newsfeed", { getUrlPrefix (item) { if (item.useCorsProxy) { - return `${location.protocol}//${location.host}/cors?url=`; + return `${location.protocol}//${location.host}${config.basePath}cors?url=`; } else { return ""; } diff --git a/modules/default/utils.js b/modules/default/utils.js index ca0166935c..12d9b36a80 100644 --- a/modules/default/utils.js +++ b/modules/default/utils.js @@ -5,13 +5,14 @@ * @param {boolean} useCorsProxy A flag to indicate * @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send * @param {Array.} expectedResponseHeaders the expected HTTP headers to receive + * @param {string} basePath, default / * @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not already contain a headers-property). */ -async function performWebRequest (url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) { +async function performWebRequest (url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined, basePath = "/") { const request = {}; let requestUrl; if (useCorsProxy) { - requestUrl = getCorsUrl(url, requestHeaders, expectedResponseHeaders); + requestUrl = getCorsUrl(url, requestHeaders, expectedResponseHeaders, basePath); } else { requestUrl = url; request.headers = getHeadersToSend(requestHeaders); @@ -37,13 +38,14 @@ async function performWebRequest (url, type = "json", useCorsProxy = false, requ * @param {string} url the url to fetch from * @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send * @param {Array.} expectedResponseHeaders the expected HTTP headers to receive + * @param {string} basePath, default / * @returns {string} to be used as URL when calling CORS-method on server. */ -const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders) { +const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders, basePath = "/") { if (!url || url.length < 1) { throw new Error(`Invalid URL: ${url}`); } else { - let corsUrl = `${location.protocol}//${location.host}/cors?`; + let corsUrl = `${location.protocol}//${location.host}${basePath}cors?`; const requestHeaderString = getRequestHeaderString(requestHeaders); if (requestHeaderString) corsUrl = `${corsUrl}sendheaders=${requestHeaderString}`; diff --git a/modules/default/weather/weatherprovider.js b/modules/default/weather/weatherprovider.js index 3646441094..0fa24a69b0 100644 --- a/modules/default/weather/weatherprovider.js +++ b/modules/default/weather/weatherprovider.js @@ -119,7 +119,7 @@ const WeatherProvider = Class.extend({ return JSON.parse(data); } const useCorsProxy = typeof this.config.useCorsProxy !== "undefined" && this.config.useCorsProxy; - return performWebRequest(url, type, useCorsProxy, requestHeaders, expectedResponseHeaders); + return performWebRequest(url, type, useCorsProxy, requestHeaders, expectedResponseHeaders, config.basePath); } });