From 923acc8294b9250cb5a714703a93d16ecbd884f6 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 13 Oct 2025 19:47:17 +0100 Subject: [PATCH] Adds warning before external request when on static mode --- src/app.d.ts | 1 + .../components/home/HomepageCategories.svelte | 5 +- src/lib/utils/deployment.ts | 14 ++++++ src/routes/diagnostics/+layout.svelte | 46 +++++++++++++------ vite.config.ts | 3 ++ 5 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/lib/utils/deployment.ts diff --git a/src/app.d.ts b/src/app.d.ts index a8265e1..5be589b 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -14,6 +14,7 @@ declare global { // Make version available globally const __APP_VERSION__: string; + const __DEPLOY_ENV__: string; } // SVG imports diff --git a/src/lib/components/home/HomepageCategories.svelte b/src/lib/components/home/HomepageCategories.svelte index 024040a..46f638e 100644 --- a/src/lib/components/home/HomepageCategories.svelte +++ b/src/lib/components/home/HomepageCategories.svelte @@ -9,6 +9,7 @@ import { extractNavItems } from '$lib/utils/nav'; import QuickTips from '$lib/components/furniture/QuickTips.svelte'; import KeyboardShortcutChip from '$lib/components/common/KeyboardShortcutChip.svelte'; + import { isStaticDeployment } from '$lib/utils/deployment'; import { onMount, onDestroy } from 'svelte'; import { browser } from '$app/environment'; @@ -41,7 +42,9 @@ } // Memoized categories - computed once at module scope (static data) - const categories: CategorySection[] = TOP_NAV.filter((nav) => nav.href !== '/reference') + const categories: CategorySection[] = TOP_NAV.filter( + (nav) => nav.href !== '/reference' && !(isStaticDeployment && nav.href === '/diagnostics'), + ) .map((nav) => { const subItems = SUB_NAV[nav.href] || []; return { diff --git a/src/lib/utils/deployment.ts b/src/lib/utils/deployment.ts new file mode 100644 index 0000000..e498dac --- /dev/null +++ b/src/lib/utils/deployment.ts @@ -0,0 +1,14 @@ +/** + * Deployment environment utilities + */ + +/** + * Check if the app is deployed to a static host (without API support) + */ +export const isStaticDeployment = __DEPLOY_ENV__ === 'static'; + +/** + * Check if API endpoints are available + */ +// export const hasApiEndpoints = !isStaticDeployment; +export const hasApiEndpoints = !isStaticDeployment; diff --git a/src/routes/diagnostics/+layout.svelte b/src/routes/diagnostics/+layout.svelte index 59ec370..9161c0c 100644 --- a/src/routes/diagnostics/+layout.svelte +++ b/src/routes/diagnostics/+layout.svelte @@ -1,10 +1,11 @@ {#if showWarning} @@ -43,13 +36,26 @@
- Limited Functionality: + Warning: {#if isOffline && isStaticDeployment} - Diagnostic tools are unavailable due to offline status and static deployment. + Diagnostic tools are unavailable while offline and on static deployments. Try using the public instance instead. {:else if isOffline} - Diagnostic tools are unavailable while offline. + Diagnostic tools are unavailable while offline. Try using the public instance instead. {:else} - Diagnostic tools will not work properly on static deployments. + Looks like you might have deployed your app to a static host. Since API endpoints are not available in your + environment, this tool won't work as expected. You can use it here instead. {/if}
@@ -93,6 +99,16 @@ font-weight: 600; color: var(--color-warning); } + + a { + color: var(--color-primary); + text-decoration: underline; + font-weight: 500; + + &:hover { + opacity: 0.8; + } + } } } diff --git a/vite.config.ts b/vite.config.ts index 53e5d4c..acae502 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,4 +12,7 @@ export default defineConfig({ }), ], envPrefix: ['VITE_', 'PUBLIC_', 'NTB_'], + define: { + __DEPLOY_ENV__: JSON.stringify(process.env.DEPLOY_ENV || ''), + }, });