Benefits of Multi-instance

EggBornJS supports the development of multiple domain sites through the concept of multiple instances

One EggBornJS service can support multiple instances, and the instances shares the same MySQL database architecture, but the data generated dynamically is isolated from each other

Application Scenarios of Multi-instance

For example, we have developed an enterprise business system to provide services to many enterprise users

Instance & Domain

The instance corresponds to the subdomain name of the website one by one, for example: instance1.cabloy.cominstance2.cabloy.com

In the test environment and development environment, EggBornJS has created a default instance; however, in the production environment, need to plan the corresponding relationship between the instance and the subdomain by yourself

Instance Configuration

Because both test environment and development environment use the default instance provided by EggBornJS, only instance parameters need to be configured for the production environment

For example, the official backend of CabloyJS hosts two instances, namely https://admin.cabloy.com and https://zhennann.cabloy.com. The configuration of it’s production environment is as follows:

/{project}/src/backend/config/config.prod.js

// instances
config.instances = [
  { subdomain: 'admin', password: '', title: 'CabloyJS', config: {} },
  { subdomain: 'zhennann', password: '', title: 'My Blog', config: {} },
  ];
Name Description
subdomain If the URL is https://cabloy.com, the corresponding subdomain is an empty string
password The initial password of the user root for this instance. The default value is 123456
title Website’s title
config instance level configuration, which will override the module level configuration automatically

How to use Mulit-instance

Reference current instance Id

Because the data between multiple instances is isolated from each other, the condition of current instance id must be taken when performing CRUD operations

// current instance id
const iid = this.ctx.instance.id;
// insert
await this.ctx.db.insert('testParty', {
  iid,
  deleted: 0,
  personCount: 3,
});
Name Description
ctx.instance current instance object
ctx.instance.id current instance id

model

The object of model further encapsulates ctx.db, which facilitates support for multi-instance and soft deletion

// insert
await this.ctx.model.party.insert({
  personCount: 3,
});