Virtual Host API

Contents

XP XP 7.6.0 7.6.0

This API provides functions for retrieving information about existing virtual host mappings.

Usage

Add the following dependency to your build.gradle file:

dependencies {
  include "com.enonic.xp:lib-vhost:${xpVersion}"
}

Add the import statement to your controller:

import vhostLib from '/lib/xp/vhost';

You are now ready to use the API.

Functions

isEnabled

Returns value which is set for the enabled property in the com.enonic.xp.web.vhost.cfg file.

Returns

Boolean : Returns true if vhost mapping is enabled, otherwise false.

Example

import vhostLib from '/lib/xp/vhost';

const isEnabled = vhostLib.isEnabled();

list

Returns list of vhost mappings which are specified in the com.enonic.xp.web.vhost.cfg file.

Returns

Object : Returns an object with vhosts array.

Example

import vhostLib from '/lib/xp/vhost';

const vhostMappings = vhostLib.list();

const vhosts = vhostMappings.vhosts;

For instance, if the com.enonic.xp.web.vhost.cfg file contains the following mapping:

mapping.admin.host = localhost
mapping.admin.source = /admin
mapping.admin.target = /admin
mapping.admin.idProvider.system = default

mapping.admintool.host = localhost
mapping.admintool.source = /admin
mapping.admintool.target = /admin
mapping.admintool.idProvider.system = default
Sample response
const expected = {
  vhosts: [
    {
      name: "admin",
      source: "/admin",
      target: "/admin",
      host: "localhost",
      defaultIdProviderKey: "system",
      idProviderKeys: [
        {
          idProviderKey: "system"
        }
      ]
    },
    {
      name: "admintool",
      source: "/admin",
      target: "/admin",
      host: "localhost",
      defaultIdProviderKey: "system",
      idProviderKeys: [
        {
          idProviderKey: "system"
        }
      ]
    }
  ]
}

Contents

Contents

AI-powered search

Juke AI