Skip to content

Commit

Permalink
fix: Use Vite BASE_URL env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mizlan committed Mar 1, 2024
1 parent 9bc5b5e commit a770001
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ const isLocalhost = Boolean(
export default function register() {
if (import.meta.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(import.meta.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
const baseUrl = new URL(import.meta.env.BASE_URL, window.location);
if (baseUrl.origin !== window.location.origin) {
// Our service worker won't work if BASE_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 = `${import.meta.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${import.meta.env.BASE_URL}/service-worker.js`;

if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
Expand Down

0 comments on commit a770001

Please sign in to comment.