Skip to content

Commit

Permalink
fix: use absolute URLs for app runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Feb 13, 2024
1 parent 369e4b8 commit 0c8bf22
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { LoadingMask } from './LoadingMask.js'
import { LoginModal } from './LoginModal.js'
import { useOfflineInterface } from './OfflineInterfaceContext.js'

// Save this location so that it's usable after client-side navigations
const originalWindowLocation = new URL(window.location)

export const ServerVersionProvider = ({
appName,
appVersion,
Expand Down Expand Up @@ -148,6 +151,9 @@ export const ServerVersionProvider = ({
return <LoadingMask />
}

// Make sure the base URL is absolute to avoid errors with relative URLs after
// client-side navigation/route changes
const absoluteBaseUrl = new URL(baseUrl, originalWindowLocation).href
const serverVersion = parseDHIS2ServerVersion(systemInfo.version)
const realApiVersion = serverVersion.minor

Expand All @@ -156,7 +162,7 @@ export const ServerVersionProvider = ({
config={{
appName,
appVersion: parseVersion(appVersion),
baseUrl,
baseUrl: absoluteBaseUrl,
apiVersion: apiVersion || realApiVersion,
serverVersion,
systemInfo,
Expand Down

0 comments on commit 0c8bf22

Please sign in to comment.