From bc32f1e89073e22ccf37637e3ae2b33ffdfd7811 Mon Sep 17 00:00:00 2001 From: Donkie Date: Fri, 10 May 2024 11:36:33 +0200 Subject: [PATCH] Now supports running under a sub path Just set the SPOOLMAN_BASE_PATH environment variable and it should work. Resolves #95 --- .env.example | 5 ++++ client/index.html | 2 +- client/src/App.tsx | 9 ++++--- client/src/components/favicon.tsx | 20 +++++++++++++++ client/src/components/layout.tsx | 3 ++- client/src/components/liveProvider.ts | 1 + client/src/components/liveify.ts | 3 ++- client/src/components/otherModels.tsx | 22 ++++++---------- client/src/components/version.tsx | 5 ++-- client/src/i18n.ts | 3 ++- client/src/pages/spools/functions.ts | 4 +-- client/src/utils/queryFields.ts | 10 +++----- client/src/utils/querySettings.ts | 10 +++----- client/src/utils/url.ts | 35 +++++++++++++++++++++++++ client/vite.config.ts | 1 + spoolman/client.py | 15 ++++++++++- spoolman/env.py | 16 ++++++++++++ spoolman/main.py | 37 ++++++++++++++++++++++++--- 18 files changed, 158 insertions(+), 43 deletions(-) create mode 100644 client/src/components/favicon.tsx create mode 100644 client/src/utils/url.ts 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 = () => {