Skip to content

Commit

Permalink
fix(SSOViews): Resolve server url when served under custom base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
strazto committed Aug 14, 2022
2 parents d09296e + 24ca176 commit a39502d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions SSO-Auth/Views/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ window.jellyfinApiclient = jellyfinApiclient;
console.log(jellyfinApiclient);

// https://github.com/jellyfin/jellyfin-web/blob/9067b0e397cc8b38635d661ce86ddd83194f3202/src/scripts/clientUtils.js#L19-L76
export async function serverAddress() {
export async function serverAddress({ basePath = "/web" }) {
const apiClient = window.ApiClient;

if (apiClient) {
Expand All @@ -12,17 +12,28 @@ export async function serverAddress() {

const urls = [];

if (urls.length === 0) {
// Otherwise use computed base URL
const getViewUrl = (basePath) => {
let url;
const index = window.location.href.toLowerCase().lastIndexOf("/web");
const index = window.location.href
.toLowerCase()
.lastIndexOf(basePath.toLowerCase());

if (index != -1) {
url = window.location.href.substring(0, index);
} else {
// fallback to location without path
url = window.location.origin;
// Return nothing, let another method handle it
url = undefined;
}

return url;
};

if (urls.length === 0) {
// Otherwise use computed base URL
let url;

url = getViewUrl(basePath) ?? getViewUrl("/web") ?? window.location.origin;

// Don't use bundled app URL (file:) as server URL
if (url.startsWith("file:")) {
return Promise.resolve();
Expand Down Expand Up @@ -103,7 +114,7 @@ await awaitLocalStorage();

var credentials = new jellyfinApiclient.Credentials();

var server = await serverAddress();
var server = await serverAddress({ basePath: "/SSOViews" });
console.log({ server: server });
var deviceId = getDeviceId();
var appName = "SSO-Auth";
Expand Down

0 comments on commit a39502d

Please sign in to comment.