From e3a5b5eaa1dca9a55cdbffba9cf5c4235a26b730 Mon Sep 17 00:00:00 2001 From: luisdralves Date: Tue, 7 May 2024 12:32:15 +0100 Subject: [PATCH] Add support for portless deploys --- .env | 1 + README.md | 4 +++- src/client/api/index.ts | 10 ++++++++-- src/client/vite-env.d.ts | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 4590401..a567e68 100644 --- a/.env +++ b/.env @@ -2,5 +2,6 @@ CLIENT_GRAPH_STEPS=150 CLIENT_PORT=3000 CLIENT_REFETCH_INTERVAL=500 SERVER_ACTIVE_WINDOW=5000 +SERVER_DEPLOY_URL= SERVER_PORT=3001 SERVER_REFRESH_INTERVAL=500 \ No newline at end of file diff --git a/README.md b/README.md index f7d45e2..5a5c27b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # SysMon Web -A system monitor for the web. Data is read with rust, and displayed on the browser via HTML canvas +A system monitor for the web. Data is read with rust, and displayed on the browser via HTML canvas. + +[Live demo](https://sysmon.bate-estacas.xyz/) ![Screenshot 2024-05-06 at 18-49-44 SysMon Web](https://github.com/luisdralves/sysmon-web/assets/22676183/af08467d-50ae-4bd1-84d8-751f03b5fe11) diff --git a/src/client/api/index.ts b/src/client/api/index.ts index d51c4ba..b998a8e 100644 --- a/src/client/api/index.ts +++ b/src/client/api/index.ts @@ -1,6 +1,12 @@ const getApiUrl = (path: string) => { - const url = new URL(window.location.href); - url.port = import.meta.env.SERVER_PORT; + let url: URL; + try { + url = new URL(import.meta.env.SERVER_DEPLOY_URL as string); + } catch { + url = new URL(window.location.href); + url.port = import.meta.env.SERVER_PORT; + } + url.pathname = path; return url; diff --git a/src/client/vite-env.d.ts b/src/client/vite-env.d.ts index 5b73224..c3ed686 100644 --- a/src/client/vite-env.d.ts +++ b/src/client/vite-env.d.ts @@ -5,6 +5,7 @@ interface ImportMetaEnv { readonly CLIENT_PORT: string; readonly CLIENT_REFETCH_INTERVAL: string; readonly SERVER_ACTIVE_WINDOW: string; + readonly SERVER_DEPLOY_URL?: string; readonly SERVER_PORT: string; readonly SERVER_REFRESH_INTERVAL: string; }