Virtual Host library
Contents
This API provides functions for retrieving information about existing virtual host mappings.
Usage
Add the following dependency to your build.gradle file:
dependencies {
include xplibs.vhost
}
Add the import statement to your code:
import vhostLib from '/lib/xp/vhost';
You are now ready to use the API.
Functions
isEnabled
Returns the value of the enabled property in the com.enonic.xp.web.vhost.cfg file.
Returns
boolean : true if vhost mapping is enabled, otherwise false.
Example
import {isEnabled} from '/lib/xp/vhost';
const enabled = isEnabled();
list
Returns the virtual host mappings configured in com.enonic.xp.web.vhost.cfg.
Returns
object : (VirtualHosts) Object with a vhosts array. The array is empty when no mappings are configured.
Example
import {list} from '/lib/xp/vhost';
const {vhosts} = list();
For instance, given the following com.enonic.xp.web.vhost.cfg:
mapping.admin.host = localhost
mapping.admin.source = /
mapping.admin.target = /admin
mapping.admin.idProvider.system = default
mapping.api.host = api.localhost
mapping.api.source = /
mapping.api.target = /api
mapping.api.idProvider.system = default
const expected = {
vhosts: [
{
name: 'admin',
source: '/',
target: '/admin',
host: 'localhost',
defaultIdProviderKey: 'system',
idProviderKeys: [
{idProviderKey: 'system'}
]
},
{
name: 'api',
source: '/',
target: '/api',
host: 'api.localhost',
defaultIdProviderKey: 'system',
idProviderKeys: [
{idProviderKey: 'system'}
]
}
]
};
Type Definitions
VirtualHosts
Type
object
Properties
| Name | Type | Description |
|---|---|---|
|
vhosts |
All configured virtual host mappings. Empty when none are configured. |
VirtualHost
Type
object
Properties
| Name | Type | Description |
|---|---|---|
|
name |
string |
Mapping name (the suffix used in |
|
source |
string |
Source path that the mapping matches. |
|
target |
string |
Target path that the mapping rewrites to. |
|
host |
string |
Host name that the mapping matches. |
|
defaultIdProviderKey |
string |
Optional. Key of the default ID provider, when configured. |
|
idProviderKeys |
Optional. ID providers attached to the mapping. |