From a6068fe23100d4c3fba6ee53d44eb3ec565f832d Mon Sep 17 00:00:00 2001 From: Mia Date: Tue, 16 Sep 2025 23:18:08 +0000 Subject: [PATCH 1/8] fix: correctly parse the path in getloc --- wled00/data/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index 5a98b4fe1f..ce86fae13e 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -86,7 +86,7 @@ function getLoc() { let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/"); if (paths.length > 1) paths.pop(); // remove subpage (or "settings") if (paths.length > 0 && paths[paths.length-1]=="settings") paths.pop(); // remove "settings" - if (paths.length > 1) { + if (paths.length > 0) { locproto = l.protocol; loc = true; locip = l.hostname + (l.port ? ":" + l.port : "") + "/" + paths.join('/'); From 414eb451710190396ee9631088b4834745259ccd Mon Sep 17 00:00:00 2001 From: Mia Date: Tue, 16 Sep 2025 23:36:08 +0000 Subject: [PATCH 2/8] fix: properly trim settings-related paths --- wled00/data/common.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index ce86fae13e..578dde87ae 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -84,8 +84,14 @@ function getLoc() { // detect reverse proxy let path = l.pathname; let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/"); - if (paths.length > 1) paths.pop(); // remove subpage (or "settings") - if (paths.length > 0 && paths[paths.length-1]=="settings") paths.pop(); // remove "settings" + + // remove settings paths to get the base url + const settingsIndex = paths.lastIndexOf("settings"); + const pathLength = paths.length; + if (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) { + paths = paths.slice(0, settingsIndex); + } + if (paths.length > 0) { locproto = l.protocol; loc = true; From 888877e4f3e785fc996dd62dfef7ab2d5c21dd25 Mon Sep 17 00:00:00 2001 From: Mia Date: Tue, 16 Sep 2025 23:40:55 +0000 Subject: [PATCH 3/8] fix: check that settings is in the path --- wled00/data/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index 578dde87ae..3762146f2e 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -88,7 +88,7 @@ function getLoc() { // remove settings paths to get the base url const settingsIndex = paths.lastIndexOf("settings"); const pathLength = paths.length; - if (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) { + if (settingsIndex != -1 && (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2)) { paths = paths.slice(0, settingsIndex); } From 50ea8323263986eb59c31c32f9fec7a18bd8ff13 Mon Sep 17 00:00:00 2001 From: Mia Date: Tue, 16 Sep 2025 23:42:09 +0000 Subject: [PATCH 4/8] fix: formatting --- wled00/data/common.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index 3762146f2e..fce31355f6 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -88,7 +88,10 @@ function getLoc() { // remove settings paths to get the base url const settingsIndex = paths.lastIndexOf("settings"); const pathLength = paths.length; - if (settingsIndex != -1 && (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2)) { + if ( + settingsIndex != -1 && + (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) + ) { paths = paths.slice(0, settingsIndex); } From 0949dd13673e4178d7d3d79147300f01af313fbc Mon Sep 17 00:00:00 2001 From: Mia Date: Tue, 16 Sep 2025 23:57:13 +0000 Subject: [PATCH 5/8] fix: cover trailing file cases and coderabbit changes --- wled00/data/common.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index fce31355f6..6492ef027d 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -89,11 +89,15 @@ function getLoc() { const settingsIndex = paths.lastIndexOf("settings"); const pathLength = paths.length; if ( - settingsIndex != -1 && + settingsIndex !== -1 && (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) ) { paths = paths.slice(0, settingsIndex); - } + } else if (paths.length && paths[paths.length - 1].includes(".")) { + // drop trailing file like index.htm + paths.pop(); + } + if (paths.length > 0) { locproto = l.protocol; From aea1a0f8fe3a5fd9604fdfb28b0f7cc2812d456f Mon Sep 17 00:00:00 2001 From: Mia Date: Thu, 18 Sep 2025 15:14:10 +0000 Subject: [PATCH 6/8] fix: simplify slice logic --- wled00/data/common.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index 6492ef027d..bca0372d51 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -87,18 +87,13 @@ function getLoc() { // remove settings paths to get the base url const settingsIndex = paths.lastIndexOf("settings"); - const pathLength = paths.length; - if ( - settingsIndex !== -1 && - (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) - ) { - paths = paths.slice(0, settingsIndex); - } else if (paths.length && paths[paths.length - 1].includes(".")) { + if (settingsIndex > 0) paths = paths.slice(0, settingsIndex); + + if (paths.length && paths[paths.length - 1].includes(".")) { // drop trailing file like index.htm paths.pop(); } - if (paths.length > 0) { locproto = l.protocol; loc = true; From e948f6840df0d7e3c2427e2be927fe3648bf07d4 Mon Sep 17 00:00:00 2001 From: Mia Date: Thu, 18 Sep 2025 18:43:54 +0000 Subject: [PATCH 7/8] fix: cleaner path logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Kristan --- wled00/data/common.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index bca0372d51..7f2abfc207 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -81,18 +81,10 @@ function getLoc() { localStorage.setItem('locIp', locip); } } else { - // detect reverse proxy - let path = l.pathname; - let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/"); - - // remove settings paths to get the base url - const settingsIndex = paths.lastIndexOf("settings"); - if (settingsIndex > 0) paths = paths.slice(0, settingsIndex); - - if (paths.length && paths[paths.length - 1].includes(".")) { - // drop trailing file like index.htm - paths.pop(); - } + // guess the base url if WLED is behind a reverse proxy + let paths = l.pathname.split("/").slice(1); // first is always empty + let settingsIndex = paths.lastIndexOf("settings"); + paths = paths.slice(0, settingsIndex); // if we don't have "settings", remove last entry (empty / or file) if (paths.length > 0) { locproto = l.protocol; From b4e13945b4354e47bfe3b27ba9c58e16ec803ed5 Mon Sep 17 00:00:00 2001 From: Mia Date: Thu, 18 Sep 2025 18:50:01 +0000 Subject: [PATCH 8/8] fix: trailing spaces --- wled00/data/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/data/common.js b/wled00/data/common.js index 7f2abfc207..bd010bb13b 100644 --- a/wled00/data/common.js +++ b/wled00/data/common.js @@ -81,7 +81,7 @@ function getLoc() { localStorage.setItem('locIp', locip); } } else { - // guess the base url if WLED is behind a reverse proxy + // guess the base url if WLED is behind a reverse proxy let paths = l.pathname.split("/").slice(1); // first is always empty let settingsIndex = paths.lastIndexOf("settings"); paths = paths.slice(0, settingsIndex); // if we don't have "settings", remove last entry (empty / or file)