mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-20 21:23:10 +03:00
Adds warning before external request when on static mode
This commit is contained in:
1 parent
0141720b31
commit
923acc8294
5 files changed
+53
-16
No files matched your search
Vendored
+1
@@ -14,6 +14,7 @@ declare global {
|
||||
|
||||
// Make version available globally
|
||||
const __APP_VERSION__: string;
|
||||
const __DEPLOY_ENV__: string;
|
||||
}
|
||||
|
||||
// SVG imports
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment';
|
||||
import { page } from '$app/stores';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { isStaticDeployment } from '$lib/utils/deployment';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let isOffline = false;
|
||||
let isStaticDeployment = false;
|
||||
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
@@ -18,16 +19,6 @@
|
||||
window.addEventListener('online', handleOnline);
|
||||
window.addEventListener('offline', handleOffline);
|
||||
|
||||
// Check for static deployment environment
|
||||
// This checks for common static deployment indicators
|
||||
isStaticDeployment =
|
||||
import.meta.env.DEPLOY_ENV === 'static' ||
|
||||
import.meta.env.DEPLOY_ENV === 'STATIC' ||
|
||||
import.meta.env.VITE_DEPLOY_ENV === 'static' ||
|
||||
import.meta.env.VITE_DEPLOY_ENV === 'STATIC' ||
|
||||
// Fallback: check if we're missing server-side features
|
||||
(typeof window !== 'undefined' && !window.fetch);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('online', handleOnline);
|
||||
window.removeEventListener('offline', handleOffline);
|
||||
@@ -36,6 +27,8 @@
|
||||
});
|
||||
|
||||
$: showWarning = isOffline || isStaticDeployment;
|
||||
$: currentPath = $page.url.pathname;
|
||||
$: publicUrl = `https://www.networkingtoolbox.net${currentPath}`;
|
||||
</script>
|
||||
|
||||
{#if showWarning}
|
||||
@@ -43,13 +36,26 @@
|
||||
<div class="warning-content">
|
||||
<Icon name="warning" size="sm" />
|
||||
<div class="warning-text">
|
||||
<strong>Limited Functionality:</strong>
|
||||
<strong>Warning:</strong>
|
||||
{#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 <a
|
||||
href={publicUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">the public instance</a
|
||||
> instead.
|
||||
{:else if isOffline}
|
||||
Diagnostic tools are unavailable while offline.
|
||||
Diagnostic tools are unavailable while offline. Try using <a
|
||||
href={publicUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">the public instance</a
|
||||
> 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 <a
|
||||
href={publicUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">here</a
|
||||
> instead.
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,4 +12,7 @@ export default defineConfig({
|
||||
}),
|
||||
],
|
||||
envPrefix: ['VITE_', 'PUBLIC_', 'NTB_'],
|
||||
define: {
|
||||
__DEPLOY_ENV__: JSON.stringify(process.env.DEPLOY_ENV || ''),
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user