stash-userscripts icon indicating copy to clipboard operation
stash-userscripts copied to clipboard

Allow userscripts to work in subpath.

Open ChilledSlim opened this issue 2 years ago • 1 comments

Within StashUserscriptLibrary.js, /graphql is hardcoded which prevents it from working in a subpath (ie: if a reverse proxy points to https://mydomain:1234/stash/ or https://mydomain:4321/apps/stash/). This causes calls to the graphql interface to throw a 404 error.

It should use the current base path as a part of that. I have tested this both by accessing via IP address (ie: http://192.168.x.x:9999/) , in a root path (https://stashapp.mydomain.com:9999), in a subpath (https://apps.mydomain.com:9999/stash/ ).

document.querySelector("head > base").href appears to work in all cases and returns correctly. This is because stash sets <base href="/stash/"> or <base href="/"> as per its configuration. Note that if that behaviour ever changes in stash, this code would need to be updated. Currently, it expands to the correct path to graphql.

ChilledSlim avatar Mar 31 '23 17:03 ChilledSlim

Sorry- this doesn't work correctly in all circumstances at this point due to the regex matching on location.href and location.origin.

Will review further in the near future and try and get it all to work nicely. Shelf this for now.

We need to include baseURL = document.querySelector("head > base").getAttribute('href') and incorporate that baseName variable in the various tests [which will be / if there is none set] -OR- simply use document.querySelector("head > base").href (which is expanded by the browser) instead of all the other logic to find the basename and test paths.

ChilledSlim avatar Mar 31 '23 18:03 ChilledSlim