getHost
Get host address based on environment configuration.
API
getHost
Return
| Argument | Description | Type |
|---|---|---|
string | undefined | Host address string | string | undefined |
Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
env | Environment name (optional) | string | Optional |
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 environmentSpecify 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
- Environment detection: If
envparameter is not provided, automatically detects environment fromwindow.location.hostname. - Server-side environment: Returns
undefinedin server-side environments (nowindowobject). - Environment mapping:
trunk,neibu,release→.${env}test→testprod→ empty string
- Return format: Returns format as
//log.${host}, wherehostvaries based on environment.