diff --git a/web/ui/mantine-ui/src/App.tsx b/web/ui/mantine-ui/src/App.tsx
index f5cbcd3bf5..ae8e08899c 100644
--- a/web/ui/mantine-ui/src/App.tsx
+++ b/web/ui/mantine-ui/src/App.tsx
@@ -60,9 +60,26 @@ import ErrorBoundary from "./ErrorBoundary";
import { ThemeSelector } from "./ThemeSelector";
import { SettingsContext } from "./settings";
import { Notifications } from "@mantine/notifications";
+import { useAppDispatch } from "./state/hooks";
+import { updateSettings } from "./state/settingsSlice";
const queryClient = new QueryClient();
+const mainNavPages = [
+ {
+ title: "Query",
+ path: "/query",
+ icon: ,
+ element: ,
+ },
+ {
+ title: "Alerts",
+ path: "/alerts",
+ icon: ,
+ element: ,
+ },
+];
+
const monitoringStatusPages = [
{
title: "Targets",
@@ -114,6 +131,7 @@ const serverStatusPages = [
];
const allStatusPages = [...monitoringStatusPages, ...serverStatusPages];
+const allPages = [...mainNavPages, ...allStatusPages];
const theme = createTheme({
colors: {
@@ -132,6 +150,21 @@ const theme = createTheme({
},
});
+// This dynamically/generically determines the pathPrefix by stripping the first known
+// endpoint suffix from the window location path. It works out of the box for both direct
+// hosting and reverse proxy deployments with no additional configurations required.
+const getPathPrefix = (path: string) => {
+ if (path.endsWith("/")) {
+ path = path.slice(0, -1);
+ }
+
+ const pagePath = allPages.find((p) => path.endsWith(p.path))?.path;
+ if (pagePath === undefined) {
+ throw new Error(`Could not find base path for ${path}`);
+ }
+ return path.slice(0, path.length - pagePath.length);
+};
+
const navLinkIconSize = 15;
const navLinkXPadding = "md";
@@ -139,26 +172,24 @@ function App() {
const [opened, { toggle }] = useDisclosure();
const { agentMode } = useContext(SettingsContext);
+ const pathPrefix = getPathPrefix(window.location.pathname);
+ const dispatch = useAppDispatch();
+ dispatch(updateSettings({ pathPrefix }));
+
const navLinks = (
<>
- }
- px={navLinkXPadding}
- >
- Query
-
- }
- px={navLinkXPadding}
- >
- Alerts
-
+ {mainNavPages.map((p) => (
+
+ ))}