mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
refactor: rename basepath to admin_basepath and normalize admin paths
This commit is contained in:
@@ -9,7 +9,7 @@ import { Message } from "ui/components/display/Message";
|
|||||||
import { useNavigate } from "ui/lib/routes";
|
import { useNavigate } from "ui/lib/routes";
|
||||||
|
|
||||||
export type BkndAdminOptions = {
|
export type BkndAdminOptions = {
|
||||||
basepath?: string;
|
admin_basepath?: string;
|
||||||
logo_return_path?: string;
|
logo_return_path?: string;
|
||||||
theme?: AppTheme;
|
theme?: AppTheme;
|
||||||
};
|
};
|
||||||
@@ -169,7 +169,7 @@ export function useBkndOptions(): BkndAdminOptions {
|
|||||||
const ctx = useContext(BkndContext);
|
const ctx = useContext(BkndContext);
|
||||||
return (
|
return (
|
||||||
ctx.options ?? {
|
ctx.options ?? {
|
||||||
basepath: "/",
|
admin_basepath: "/",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,23 @@ import type { BkndAdminOptions } from "ui/client/BkndProvider";
|
|||||||
|
|
||||||
export type AppType = ReturnType<App["toJSON"]>;
|
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
|
* Reduced version of the App class for frontend use
|
||||||
* @todo: remove this class
|
* @todo: remove this class
|
||||||
@@ -68,20 +85,19 @@ export class AppReduced {
|
|||||||
|
|
||||||
get options() {
|
get options() {
|
||||||
return {
|
return {
|
||||||
basepath: "",
|
admin_basepath: "",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
...this._options,
|
...this._options,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettingsPath(path: string[] = []): string {
|
getSettingsPath(path: string[] = []): string {
|
||||||
const base = `~/${this.options.basepath}/settings`.replace(/\/+/g, "/");
|
const base = `~/${this.options.admin_basepath}/settings`
|
||||||
return [base, ...path].join("/");
|
return normalizeAdminPath([base, ...path].join("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
getAbsolutePath(path?: string): string {
|
getAbsolutePath(path?: string): string {
|
||||||
const { basepath } = this.options;
|
return normalizeAdminPath((path ? `~/${this.options.admin_basepath}/${path}` : `~/${this.options.admin_basepath}`));
|
||||||
return (path ? `~/${basepath}/${path}` : `~/${basepath}`).replace(/\/+/g, "/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuthConfig() {
|
getAuthConfig() {
|
||||||
|
|||||||
Reference in New Issue
Block a user