<commit_before>/* @flow */

import {getExternalIP} from './external-ip'

const BASE = 'xip.io'

function isValidIpv4Addr(ip) {
  return /^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(ip)
}

export function getXIPSubdomain() {
  const externalIP = getExternalIP()

  if (externalIP === '127.0.0.1') {
    // shorten
    return `0.${BASE}`
  }

  if (isValidIpv4Addr(externalIP)) {
    // invalid IP address, fallback to local
    return `0.${BASE}`
  }

  return `${externalIP}.${BASE}`<commit_msg>Fix NAVY_EXTERNAL_IP and NAVY_HOST not working<commit_after>/* @flow */

import {getExternalIP} from './external-ip'

const BASE = 'xip.io'

function isValidIpv4Addr(ip) {
  return /^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/g.test(ip)
}

export function getXIPSubdomain() {
  const externalIP = getExternalIP()

  if (externalIP === '127.0.0.1') {
    // shorten
    return `0.${BASE}`
  }

  if (isValidIpv4Addr(externalIP)) {
    // invalid IP address, fallback to local
    return `0.${BASE}`
  }

  return `${externalIP}.${BASE}`
{'fraction_non_alphanumeric': 0.2671118530884808, 'fraction_numerical': 0.08347245409015025, 'mean_word_length': 3.5416666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340020', 'n_tokens_mistral': 572, 'n_tokens_neox': 557, 'n_words': 78}