diff --git a/src/layouts/DefaultLayout.vue b/src/layouts/DefaultLayout.vue
index 46f8af080..fba112e91 100644
--- a/src/layouts/DefaultLayout.vue
+++ b/src/layouts/DefaultLayout.vue
@@ -146,6 +146,14 @@
+
+ Backend is unavailable
+
@@ -162,9 +170,10 @@ import SplashScreen from '@/components/general/SplashScreen.vue'
import GlobalSearchComponent from '@/components/general/GlobalSearchComponent.vue'
import { configManager } from '@/services/application-config'
-import { getResourcesStaticUrl } from '@/lib/fews-config'
+import { getResourcesStaticUrl, isBackendAvailable } from '@/lib/fews-config'
import { StyleValue, nextTick } from 'vue'
import packageConfig from '../../package.json'
+import { asyncComputed } from '@vueuse/core'
const configStore = useConfigStore()
const alertsStore = useAlertsStore()
@@ -181,6 +190,11 @@ const logoSrc = ref('')
const splashSrc = ref()
const appBarStyle = ref()
const appBarColor = ref('')
+const HEALTH_CHECK_TIMEOUT = 5000
+const showBackendError = asyncComputed(
+ async () => !(await isBackendAvailable(HEALTH_CHECK_TIMEOUT)),
+ false,
+)
function updateAppBarColor() {
appBarColor.value = getComputedStyle(document.body).getPropertyValue(
diff --git a/src/lib/fews-config/index.ts b/src/lib/fews-config/index.ts
index b8068fd16..33c768c70 100644
--- a/src/lib/fews-config/index.ts
+++ b/src/lib/fews-config/index.ts
@@ -44,3 +44,29 @@ export function getResourcesIconsUrl(resource: string) {
})
return webServiceProvider.resourcesIconsUrl(resource).toString()
}
+
+export async function isBackendAvailable(timeout?: number) {
+ const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
+
+ const controller = new AbortController()
+ const DEFAULT_TIMEOUT = 5000
+ const timeoutId = setTimeout(
+ () => controller.abort(),
+ timeout ?? DEFAULT_TIMEOUT,
+ )
+
+ const webServiceProvider = new PiWebserviceProvider(baseUrl, {
+ transformRequestFn: createTransformRequestFn(controller),
+ })
+
+ try {
+ await webServiceProvider.getVersion()
+ } catch (e) {
+ if (e instanceof Error && e.name === 'AbortError') {
+ return false
+ }
+ }
+
+ clearTimeout(timeoutId)
+ return true
+}