Skip to content

Commit

Permalink
Update isRunningLocally Function to Recognise Private IP Addresses …
Browse files Browse the repository at this point in the history
…for Consistent GUI Rendering (#2223)

* Update index.js

Signed-off-by: Sajid Alam <[email protected]>

* Update src/utils/index.js

Co-authored-by: Jitendra Gundaniya <[email protected]>
Signed-off-by: Sajid Alam <[email protected]>

---------

Signed-off-by: Sajid Alam <[email protected]>
Signed-off-by: Sajid Alam <[email protected]>
Co-authored-by: Jitendra Gundaniya <[email protected]>
  • Loading branch information
SajidAlamQB and jitu5 authored Dec 11, 2024
1 parent 8cf8617 commit ae19e10
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,38 @@ export const formatNumberWithCommas = (number) => {
};

/**
* Test if Kedro-Viz is running on our known local ports.
* Test if Kedro-Viz is running on our known local ports or private IP ranges.
* @returns {Boolean} True if the app is running locally.
*/
export const isRunningLocally = () => {
const hosts = [
'localhost',
'127.0.0.1',
'0.0.0.0',
'demo.kedro.org',
'gitpod',
'kedro-org',
];
const itemFound = hosts.some((host) =>
window.location.hostname.includes(host)
);

return itemFound;
const hostname = window.location.hostname.toLowerCase();

// Check if hostname matches known hosts
if (hosts.some((host) => hostname.includes(host))) {
return true;
}

// Regular expressions for private IP ranges
const privateIpRanges = [
// 10.0.0.0 – 10.255.255.255
/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,
// 172.16.0.0 – 172.31.255.255
/^172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3}$/,
// 192.168.0.0 – 192.168.255.255
/^192\.168\.\d{1,3}\.\d{1,3}$/,
];

// Check if hostname is a private IP address
return privateIpRanges.some((regex) => regex.test(hostname));
};

/**
Expand Down

0 comments on commit ae19e10

Please sign in to comment.