Skip to content

Instantly share code, notes, and snippets.

@davej
Created April 9, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davej/d025e5b6c6570eae87a280f307477eee to your computer and use it in GitHub Desktop.
Save davej/d025e5b6c6570eae87a280f307477eee to your computer and use it in GitHub Desktop.
Detect if current hostname is local
const isLocalhostName = window.location.hostname === 'localhost';
const isLocalhostIPv6 = window.location.hostname === '[::1]';
const isLocalhostIPv4 = window.location.hostname.match(
// 127.0.0.1/8
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
);
const isLocalhost = isLocalhostName || isLocalhostIPv6 || isLocalhostIPv4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment