diff --git a/htdocs/test/apitest.js b/htdocs/test/apitest.js index fd9624307..6746ab952 100644 --- a/htdocs/test/apitest.js +++ b/htdocs/test/apitest.js @@ -5,6 +5,8 @@ https://github.com/jcorporation/mympd */ +const subdir = window.location.pathname.replace('/test/apitest.html', '').replace(/\/$/, ''); + const cmds = Object.keys(APImethods); let i = 0; let error = 0; @@ -51,7 +53,7 @@ async function sendAPI(method) { const request = {"jsonrpc": "2.0", "id": 0, "method": method, "params": apiParamsToObject(APImethods[method].params)}; document.getElementsByTagName('h5')[0].textContent = 'Running ' + JSON.stringify(request); time_start = new Date().getTime(); - const uri = '/api/default'; + const uri = subdir + '/api/default'; const response = await fetch(uri, { method: 'POST', mode: 'same-origin', diff --git a/htdocs/test/fuzzer.js b/htdocs/test/fuzzer.js index b6f75e723..4d10327b4 100644 --- a/htdocs/test/fuzzer.js +++ b/htdocs/test/fuzzer.js @@ -11,6 +11,8 @@ let t = 0; const blns_len = blns.length; let cmds; +const subdir = window.location.pathname.replace('/test/fuzzer.html', '').replace(/\/$/, ''); + function defineCmds() { let newCmds = []; for (const method in APImethods) { @@ -99,7 +101,7 @@ async function sendAPI(id) { } const request = cmds[id]; let sleep = 0; - const uri = '/api/default'; + const uri = subdir + '/api/default'; const response = await fetch(uri, { method: 'POST', mode: 'same-origin', diff --git a/htdocs/test/manual.js b/htdocs/test/manual.js index 76a5956a7..1ec99fc77 100644 --- a/htdocs/test/manual.js +++ b/htdocs/test/manual.js @@ -7,6 +7,8 @@ /* global cmds */ +const subdir = window.location.pathname.replace('/test/manual.html', '').replace(/\/$/, ''); + //escapes html characters to avoid xss function e(x) { if (x!== undefined && isNaN(x)) { @@ -119,7 +121,7 @@ async function sendAPI() { if (APImethods[method].params !== undefined) { request.params = formToParams(APImethods[method].params, ''); } - const uri = '/api/' + partition; + const uri = subdir + '/api/' + partition; document.getElementById('requestText').textContent = JSON.stringify(request); const time_start = new Date().getTime(); const response = await fetch(uri, {