defineNuxtMultiTenancyConfig

Gitlab
Configure the multi-tenancy config for the Nuxt application.
You should use this function in your tenants.config.ts file. When you want to use a different filename, you can use the configFile option to configure the filename.

Usage

The defineNuxtMultiTenancyConfig utility is used to define the multi-tenancy config.

It accepts a function or promise that returns an array of tenant configurations, or an array of tenant configurations directly.

This function will be called before the Nuxt application initializes the site config from @nuxtjs/seo.

Basic example

tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: ["localhost:3000"],
// ... }]);

Async example

You might want to load the tenant configurations or parts of the configuration from a external source. You can do this by using an async function.

tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
(async () => {
// Any async code here... return [{
hosts
: ["localhost:3000"],
// ... }]; });

Type Definition

function 
defineNuxtMultiTenancyConfig
<
T
extends
TenantConfig
>(
config
:
T
[] | (() =>
T
[] |
Promise
<
T
[]>)):
Promise
<
T
[]>;

API Reference

Params

config
T[] | (() => T[] | Promise<T[]>)
Accepts a function or promise that returns an array of tenant configurations, or an array of tenant configurations directly.

Take a look at the configuration section for more information on what properties are available / required.

Return Value

Promise<T[]>
The defined config.

Configuration

The defineNuxtMultiTenancyConfig function returns a promise that resolves to an array of tenant configurations. Below you can find the properties that are available / required for the tenant configuration.

Alternatively, see the TenantConfig type definition for more information.


hosts
string[] required
Use the hosts option to set the hosts of the tenants.
Should be without the protocol (http/https) and www prefix.
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [
"canonicalurl.nl", "canonical.staging.dev", ], // ... }])
config.url
string required
Use the url option to set the canonical Site URL of the tenant.
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [],
config
: {
url
: "https://canonicalurl.nl",
// ... }, }])
config.name
string required
The name of the site.
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [],
config
: {
url
: "https://canonicalurl.nl",
name
: "Canonical URL",
// ... }, }])
config.tenant.id
string required
The id of the tenant.
Will also be used to generate a localhost URL for the tenant. (e.g. http://canonical.localhost:3000)
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [],
config
: {
url
: "https://canonicalurl.nl",
name
: "Canonical URL",
tenant
: {
id
: "canonical",
// ... }, }, }])
config.tenant.site
Record<string, string> required
The sites of the tenant.
The key is the locale and the value is the site handle.
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [],
config
: {
url
: "https://canonicalurl.nl",
name
: "Canonical URL",
tenant
: {
site
: {
"nl-NL": "canonical-nl-NL", }, // ... }, }, }])
The public runtime config of the tenant.
Accepts the same keys as the publicRuntimeConfig option of the nuxt.config.ts file.
tenants.config.ts
export default 
defineNuxtMultiTenancyConfig
([{
hosts
: [],
config
: {
url
: "https://canonicalurl.nl",
name
: "Canonical URL",
tenant
: {
publicRuntimeConfig
: {
scripts
: {
googleTagManager
: {
id
: "",
}, }, }, }, }, }])

Changelog