From dc749462ec09d2e6b7b5e4372bb035d80e6b5ee2 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 10 Nov 2018 23:43:48 +0900 Subject: [PATCH] automatically detect the btcpay server url in btcpay.js --- BTCPayServer/Views/Invoice/ListInvoices.cshtml | 4 ---- BTCPayServer/wwwroot/modal/btcpay.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 072e77354..3ca994084 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -6,10 +6,6 @@ @section HeadScripts { - - }
diff --git a/BTCPayServer/wwwroot/modal/btcpay.js b/BTCPayServer/wwwroot/modal/btcpay.js index 557b7c80d..dd0f0675e 100644 --- a/BTCPayServer/wwwroot/modal/btcpay.js +++ b/BTCPayServer/wwwroot/modal/btcpay.js @@ -1,5 +1,19 @@ /* jshint browser: true, strict: false, maxlen: false, maxstatements: false */ (function () { + var supportsCurrentScript = ("currentScript" in document); + var thisScript = ""; + if (supportsCurrentScript) { + thisScript = document.currentScript.src; + } + else { + for (var i = 0; i < document.scripts.length; i++) { + var script = document.scripts[i]; + if (script.src.endsWith("btcpay.js")) { + thisScript = script.src; + } + } + } + function warn() { if (window.console && window.console.warn) { window.console.warn.apply(window.console, arguments); @@ -25,6 +39,10 @@ iframe.style.zIndex = '2000'; var origin = 'http://slack.btcpayserver.org join us there, and initialize this with your origin url through setApiUrlPrefix'; + if (thisScript.endsWith("/modal/btcpay.js")) { + // We can't just take the domain as btcpay can run under a sub path with RootPath + origin = thisScript.substr(0, thisScript.length - "/modal/btcpay.js".length); + } // urlPrefix should be site root without trailing slash function setApiUrlPrefix(urlPrefix) { origin = stripTrailingSlashes(urlPrefix);