Skip to content

Commit

Permalink
update serviceWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
vLSHTM committed Feb 15, 2024
1 parent b716f1c commit 00c63c4
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions client/src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.

const isLocalhost = Boolean(
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
// const isLocalhost = Boolean(
// window.location.hostname === "localhost" ||
// // [::1] is the IPv6 localhost address.
// window.location.hostname === "[::1]" ||
// // 127.0.0.1/8 is considered localhost for IPv4.
// window.location.hostname.match(
// /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
// )
// );

export default function register() {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
if (!process.env.PUBLIC_URL && process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return;
}
// const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
// if (publicUrl.origin !== window.location.origin) {
// // Our service worker won't work if PUBLIC_URL is on a different origin
// // from what our page is served on. This might happen if a CDN is used to
// // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
// return;
// }

window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
// window.addEventListener("load", () => {
// const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

if (!isLocalhost) {
// Is not local host. Just register service worker
registerValidSW(swUrl);
} else {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);
}
});
// if (!isLocalhost) {
// // Is not local host. Just register service worker
// registerValidSW(swUrl);
// } else {
// // This is running on localhost. Lets check if a service worker still exists or not.
// checkValidServiceWorker(swUrl);
// }
// });
}
}

Expand Down

0 comments on commit 00c63c4

Please sign in to comment.