Skip to content

Instantly share code, notes, and snippets.

@chrisvoo
Created February 21, 2019 08:27
Show Gist options
  • Save chrisvoo/93d58f8f2fd411f5ed8b3f5558dee3b4 to your computer and use it in GitHub Desktop.
Save chrisvoo/93d58f8f2fd411f5ed8b3f5558dee3b4 to your computer and use it in GitHub Desktop.
Tests if the scripts is running in local (taken from registerServiceWorker.js - CRA apps)
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}$/,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment