Skip to content

Commit

Permalink
fix(page): use qualified url for service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Jul 15, 2024
1 parent 3803877 commit c5f760d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 55 deletions.
3 changes: 2 additions & 1 deletion apps/page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"multimatch": "7.0.0",
"@m31coding/fuzzy-search": "1.0.1",
"color.js": "1.2.0",
"farbraum": "0.2.1"
"farbraum": "0.2.1",
"object-code": "1.3.3"
},
"devDependencies": {
"tailwindcss": "3.0.24",
Expand Down
37 changes: 0 additions & 37 deletions apps/page/src/features/LoadingOverlay.vue

This file was deleted.

2 changes: 0 additions & 2 deletions apps/page/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import PageFooter from '../features/PageFooter.vue';
import LoadingBar from '../features/LoadingBar.vue';
import Subscribe from '../features/subscribe/Subscribe.vue';
import Colors from '../features/Colors.vue';
import LoadingOverlay from '../features/LoadingOverlay.vue';
import { store } from '../logic';
import { getLanguage } from '../i18n';
Expand All @@ -32,7 +31,6 @@ const lang = getLanguage();
</head>
<body>
<Colors client:only="vue" />
<LoadingOverlay client:load />
<LoadingBar client:only="vue" />
<PageHeader client:idle transition:persist="header" />
<main transition:animate="fade">
Expand Down
16 changes: 3 additions & 13 deletions apps/page/src/lib/caching.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { hash } from 'object-code';

export const etag = async (input: any): Promise<string> => {
const entity = JSON.stringify(input);

const textAsBuffer = new TextEncoder().encode(entity);
const hashBuffer = await crypto.subtle.digest("SHA-1", textAsBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hash = hashArray
.map((item) => item.toString(16).padStart(2, "0"))
.join("");

const len = Buffer.byteLength(entity, 'utf8');

return len.toString(16) + '-' + Buffer.from(hash).toString('base64').substring(0, 27);
export const etag = async (input: { data: any, version: string }): Promise<string> => {
return `${input.version}-${hash(input.data)}`;
}
7 changes: 5 additions & 2 deletions apps/page/src/logic/sagas/serviceworker.sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export default ({

const feed: string = yield select(selectFeed);
const cacheKey: string = yield select(selectCacheKey);
const baseUrl = new URL(document.location.href);

const serviceWorkerUrl = `${baseUrl.origin}${serviceWorker}?feed=${feed}&cacheKey=${cacheKey}`;

try {
const registration: ServiceWorkerRegistration = yield navigator.serviceWorker.register(
`${serviceWorker}?feed=${feed}&cacheKey=${cacheKey}`,
serviceWorkerUrl,
{
scope: '/'
}
Expand All @@ -35,7 +38,7 @@ export default ({

return function* () {
if(import.meta.env.MODE === 'production') {
yield registerServiceWorker();
yield registerServiceWorker();
}
};
};
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5f760d

Please sign in to comment.