refactor: rename basepath to admin_basepath and normalize admin paths

This commit is contained in:
cameronapak
2025-07-22 08:28:23 -05:00
parent c833b2b539
commit f07f3d1007
2 changed files with 23 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ import { Message } from "ui/components/display/Message";
import { useNavigate } from "ui/lib/routes";
export type BkndAdminOptions = {
basepath?: string;
admin_basepath?: string;
logo_return_path?: string;
theme?: AppTheme;
};
@@ -169,7 +169,7 @@ export function useBkndOptions(): BkndAdminOptions {
const ctx = useContext(BkndContext);
return (
ctx.options ?? {
basepath: "/",
admin_basepath: "/",
}
);
}

View File

@@ -6,6 +6,23 @@ import type { BkndAdminOptions } from "ui/client/BkndProvider";
export type AppType = ReturnType<App["toJSON"]>;
/**
* Normalize admin path by removing duplicate slashes and ensuring proper format
* @param path - The path to normalize
* @returns Normalized path
* @private
*/
function normalizeAdminPath(path: string): string {
// Remove duplicate slashes
const normalized = path.replace(/\/+/g, "/");
// Don't remove trailing slash if it's the only character or if path ends with entity/
if (normalized === "/" || normalized.endsWith("/entity/")) {
return normalized;
}
// Remove trailing slash for other paths
return normalized.replace(/\/$/, "") || "/";
}
/**
* Reduced version of the App class for frontend use
* @todo: remove this class
@@ -68,20 +85,19 @@ export class AppReduced {
get options() {
return {
basepath: "",
admin_basepath: "",
logo_return_path: "/",
...this._options,
};
}
getSettingsPath(path: string[] = []): string {
const base = `~/${this.options.basepath}/settings`.replace(/\/+/g, "/");
return [base, ...path].join("/");
const base = `~/${this.options.admin_basepath}/settings`
return normalizeAdminPath([base, ...path].join("/"));
}
getAbsolutePath(path?: string): string {
const { basepath } = this.options;
return (path ? `~/${basepath}/${path}` : `~/${basepath}`).replace(/\/+/g, "/");
return normalizeAdminPath((path ? `~/${this.options.admin_basepath}/${path}` : `~/${this.options.admin_basepath}`));
}
getAuthConfig() {