Skip to content

Commit

Permalink
attempt: Fix import.meta.env problems
Browse files Browse the repository at this point in the history
  • Loading branch information
mizlan committed Mar 1, 2024
1 parent cf6a7b5 commit 8896f0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/firebase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getConfig = () => {
}
if (import.meta.env.VITE_DB === 'prod') {
// NOTE: Netlify secret
config = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG);
config = JSON.parse(import.meta.env.REACT_APP_FIREBASE_CONFIG);
}
return config;
};
Expand Down
20 changes: 10 additions & 10 deletions src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
// This link also includes instructions on opting out of this behavior.

const isLocalhost = Boolean(
window.location.hostname === 'localhost'
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
|| window.location.hostname === '[::1]'
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}$/),
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 (import.meta.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);
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
// from what our page is served on. This might happen if a CDN is used to
Expand All @@ -28,7 +28,7 @@ export default function register() {
}

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

if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
Expand All @@ -38,8 +38,8 @@ export default function register() {
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service '
+ 'worker. To learn more, visit https://goo.gl/SC7cgQ',
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ',
);
});
} else {
Expand Down Expand Up @@ -85,8 +85,8 @@ function checkValidServiceWorker(swUrl) {
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404
|| response.headers.get('content-type').indexOf('javascript') === -1
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then((registration) => {
Expand Down

0 comments on commit 8896f0f

Please sign in to comment.