Skip to content

getHost

Get host address based on environment configuration.

API

getHost

Return

ArgumentDescriptionType
string | undefinedHost address stringstring | undefined

Parameters

ParameterDescriptionTypeDefault
envEnvironment name (optional)stringOptional

Example

Basic Usage

js
import { getHost } from 'ranuts';

// Automatically detect environment from window.location.hostname
const host = getHost();
console.log(host); // Returns corresponding host address based on current environment

Specify Environment

js
import { getHost } from 'ranuts';

const trunkHost = getHost('trunk');
console.log(trunkHost); // '//log..trunk'

const testHost = getHost('test');
console.log(testHost); // '//log.test'

const prodHost = getHost('prod');
console.log(prodHost); // '//log.'

Environment Detection Rules

js
import { getHost } from 'ranuts';

// trunk/neibu/release environments
getHost('trunk'); // '//log..trunk'
getHost('neibu'); // '//log..neibu'
getHost('release'); // '//log..release'

// test environment
getHost('test'); // '//log.test'

// prod environment
getHost('prod'); // '//log.'

Notes

  1. Environment detection: If env parameter is not provided, automatically detects environment from window.location.hostname.
  2. Server-side environment: Returns undefined in server-side environments (no window object).
  3. Environment mapping:
    • trunk, neibu, release.${env}
    • testtest
    • prod → empty string
  4. Return format: Returns format as //log.${host}, where host varies based on environment.

Released under the MIT License.