diff --git a/.env.example b/.env.example index 15fcd60..391990b 100644 --- a/.env.example +++ b/.env.example @@ -35,6 +35,11 @@ SPOOLMAN_HOST=0.0.0.0 SPOOLMAN_PORT=7912 +# Change base path +# Set this if you want to host Spoolman at a sub-path +# If you want the root to be e.g. myhost.com/spoolman +# Then set this to /spoolman +#SPOOLMAN_BASE_PATH= # Enable Collect Prometheus metrics at database # Default: FALSE diff --git a/client/index.html b/client/index.html index 14fb6df..54cf622 100644 --- a/client/index.html +++ b/client/index.html @@ -2,12 +2,12 @@ - + Spoolman diff --git a/client/src/App.tsx b/client/src/App.tsx index fbcddf3..85f5ad4 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -26,6 +26,8 @@ import loadable from "@loadable/component"; import SpoolmanNotificationProvider from "./components/notificationProvider"; import { SpoolmanLayout } from "./components/layout"; import liveProvider from "./components/liveProvider"; +import { getAPIURL, getBasePath } from "./utils/url"; +import { Favicon } from "./components/favicon"; interface ResourcePageProps { resource: "spools" | "filaments" | "vendors"; @@ -84,7 +86,7 @@ function App() { } return ( - + + diff --git a/client/src/components/favicon.tsx b/client/src/components/favicon.tsx new file mode 100644 index 0000000..64d1a02 --- /dev/null +++ b/client/src/components/favicon.tsx @@ -0,0 +1,20 @@ +import { useEffect } from "react"; + +/** + * Renders a favicon element in the head of the HTML document with the specified URL. + * + * @param {string} props.url - The URL of the favicon image. + * @return {JSX.Element} - An empty JSX element. + */ +export function Favicon(props: { url: string }) { + useEffect(() => { + let link = document.querySelector("link[rel~='icon']") as HTMLLinkElement; + if (!link) { + link = document.createElement("link") as HTMLLinkElement; + link.rel = "icon"; + document.getElementsByTagName("head")[0].appendChild(link); + } + link.href = props.url; + }, [props.url]); + return <>; +} diff --git a/client/src/components/layout.tsx b/client/src/components/layout.tsx index 32177b9..36b7ada 100644 --- a/client/src/components/layout.tsx +++ b/client/src/components/layout.tsx @@ -5,6 +5,7 @@ import { Version } from "./version"; import { Button } from "antd"; import Logo from "../icon.svg?react"; import { useTranslate } from "@refinedev/core"; +import { getBasePath } from "../utils/url"; const SpoolmanFooter: React.FC = () => { const t = useTranslate(); @@ -27,7 +28,7 @@ const SpoolmanFooter: React.FC = () => {