From 47587812b809fee2a95c76266d9d0e42fc4ac1ca Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 15 Jun 2021 14:14:28 +0800 Subject: ... --- FrontEnd/src/sw/sw.ts | 62 ------------------------------------------- FrontEnd/src/sw/tsconfig.json | 12 --------- 2 files changed, 74 deletions(-) delete mode 100644 FrontEnd/src/sw/sw.ts delete mode 100644 FrontEnd/src/sw/tsconfig.json (limited to 'FrontEnd/src/sw') diff --git a/FrontEnd/src/sw/sw.ts b/FrontEnd/src/sw/sw.ts deleted file mode 100644 index 724804dd..00000000 --- a/FrontEnd/src/sw/sw.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { precacheAndRoute, matchPrecache } from "workbox-precaching"; -import { registerRoute, setDefaultHandler } from "workbox-routing"; -import { - NetworkFirst, - NetworkOnly, - StaleWhileRevalidate, -} from "workbox-strategies"; -import { CacheableResponsePlugin } from "workbox-cacheable-response"; -import { ExpirationPlugin } from "workbox-expiration"; - -declare let self: ServiceWorkerGlobalScope; - -self.addEventListener("message", (event) => { - if (event.data && (event.data as { type: string }).type === "SKIP_WAITING") { - void self.skipWaiting(); - } -}); - -precacheAndRoute(self.__WB_MANIFEST); - -const networkOnly = new NetworkOnly(); - -registerRoute(new RegExp("/swagger/?.*"), new NetworkOnly()); - -registerRoute(new RegExp("/api/token/?.*"), new NetworkOnly()); -registerRoute(new RegExp("/api/search/?.*"), new NetworkOnly()); - -registerRoute( - new RegExp("/api/users/.+/avatar"), - new StaleWhileRevalidate({ - cacheName: "avatars", - plugins: [ - new CacheableResponsePlugin({ - statuses: [200], - }), - new ExpirationPlugin({ - maxAgeSeconds: 60 * 60 * 24 * 30 * 3, // 3 months - }), - ], - }) -); - -registerRoute( - new RegExp("/api/?.*"), - new NetworkFirst({ - plugins: [ - new CacheableResponsePlugin({ - statuses: [200], - }), - ], - }) -); - -setDefaultHandler((options) => { - const { request } = options; - - if (request instanceof Request && request.destination === "document") - return matchPrecache("/index.html").then((r) => - r == null ? Response.error() : r - ); - else return networkOnly.handle(options); -}); diff --git a/FrontEnd/src/sw/tsconfig.json b/FrontEnd/src/sw/tsconfig.json deleted file mode 100644 index 71fc0bcd..00000000 --- a/FrontEnd/src/sw/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "lib": [ - "esnext", - "webworker" - ] - }, - "include": [ - "." - ] -} -- cgit v1.2.3