- introduce Dockerfile for Python environment setup - create FastAPI app with authentication and user management - implement server management features with CRUD operations - add PWA support with service worker and manifest - set up initial templates for UI components 📝 docs(fleetledger): add README for FleetLedger application - describe app features and functionalities - provide security notes and quick start guide 📦 build(fleetledger): configure Docker and docker-compose setup - define Dockerfile for application container - create docker-compose.yml for service orchestration - specify environment variables and volumes for persistence
74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
const CACHE_VERSION = "v2";
|
|
const CACHE_NAME = `fleetledger-${CACHE_VERSION}`;
|
|
const ASSETS = [
|
|
"/",
|
|
"/static/style.css",
|
|
"/static/icon-192.png",
|
|
"/static/icon-512.png",
|
|
"/static/manifest.webmanifest",
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(ASSETS);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(
|
|
keys
|
|
.filter((key) => key.startsWith("fleetledger-") && key !== CACHE_NAME)
|
|
.map((key) => caches.delete(key))
|
|
)
|
|
)
|
|
);
|
|
});
|
|
|
|
async function networkFirst(request) {
|
|
try {
|
|
const response = await fetch(request);
|
|
const cache = await caches.open(CACHE_NAME);
|
|
cache.put(request, response.clone());
|
|
return response;
|
|
} catch (err) {
|
|
const cached = await caches.match(request);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
return caches.match("/");
|
|
}
|
|
}
|
|
|
|
async function cacheFirst(request) {
|
|
const cached = await caches.match(request);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
const response = await fetch(request);
|
|
const cache = await caches.open(CACHE_NAME);
|
|
cache.put(request, response.clone());
|
|
return response;
|
|
}
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
if (event.request.method !== "GET") {
|
|
return;
|
|
}
|
|
|
|
const url = new URL(event.request.url);
|
|
|
|
// Navigation requests: network first, fallback to cache
|
|
if (event.request.mode === "navigate") {
|
|
event.respondWith(networkFirst(event.request));
|
|
return;
|
|
}
|
|
|
|
// Same-origin static assets: cache first
|
|
if (url.origin === self.location.origin) {
|
|
event.respondWith(cacheFirst(event.request));
|
|
}
|
|
});
|