-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Get the API root location from the current window path | ||
*/ | ||
export function getRootPath(): string { | ||
return extract(window.location.pathname); | ||
} | ||
|
||
/** | ||
* Get the full API root URL from the current page href | ||
*/ | ||
export function getPublicURL(): string { | ||
return extract(window.location.href); | ||
} | ||
|
||
/** | ||
* Extract the root path of the admin app from a given input path/url | ||
* | ||
* @param path - Path or URL string of the current page | ||
* @returns - Root URL of the Directus instance | ||
*/ | ||
export function extract(path: string) { | ||
const parts = path.split("/"); | ||
const adminIndex = parts.indexOf("admin"); | ||
const rootPath = parts.slice(0, adminIndex).join("/") + "/"; | ||
return rootPath; | ||
} |