I want to have a check in my javascript if the page loading up is on my local machine.
The reason why I want to do that is that when I developing I like to make sure
This one also covers some common cases where local network IPs start with 10.0.
or 192.168.
or Bonjour like domain ending on .local
:
export function isLocalNetwork(hostname = window.location.hostname) {
return (
(['localhost', '127.0.0.1', '', '::1'].includes(hostname))
|| (hostname.startsWith('192.168.'))
|| (hostname.startsWith('10.0.'))
|| (hostname.endsWith('.local'))
)
}