add offline support
Sonarqube Scanner / Prepare environment (push) Successful in 14s
Sonarqube Scanner / Build and test (push) Successful in 22s
Sonarqube Scanner / SonarQube analysis (push) Failing after 1m14s
Sonarqube Scanner / Deploy to Server (push) Successful in 11s

This commit is contained in:
Florian Zumpe
2026-09-30 23:27:42 +02:00
parent 6913024af1
commit 8f4664282b
16 changed files with 1134 additions and 4 deletions
+27 -2
View File
@@ -1,8 +1,33 @@
(function (ns, $) {
'use strict';
function request(path) {
return $.ajax({ url: ns.Config.apiBase + path, method: 'GET', dataType: 'json', cache: false });
async function offlineResponse(path) {
if (!ns.OfflineStore) return null;
if (path === '/health') {
const available = await ns.OfflineStore.state() || (await ns.OfflineStore.routes()).length;
return available ? { ok: true, offline: true } : null;
}
if (path.startsWith('/routes?')) {
if (!await ns.OfflineStore.state() && !(await ns.OfflineStore.routes()).length) return null;
return { routes: (await ns.OfflineStore.routes()).map(item => item.route), offline: true };
}
const response = await ns.OfflineStore.match(ns.Config.apiBase + path);
return response ? response.json() : null;
}
async function request(path) {
if (globalThis.navigator?.onLine === false) {
const response = await offlineResponse(path);
if (response) return response;
}
try {
return await $.ajax({ url: ns.Config.apiBase + path, method: 'GET', dataType: 'json', cache: false, timeout: 10000 });
} catch (error) {
if (error.status > 0) throw error;
const response = await offlineResponse(path);
if (response) return response;
throw error;
}
}
function routeQuery(position) {