Step-by-Step Guide to Utilizing Empress' Sites Feature

Introduction

Welcome to this comprehensive guide on Empress’ Sites feature. As developers, it is essential to understand the nuances of this feature for the effective development, customization, and maintenance of your applications.

Introduction

Empress is a multi-tenant platform, and in its ecosystem, each tenant is represented as a site. A site operates with its own database and is stored in a directory named sites. This directory is assumed to be the current working directory when executing a bench command.

The Sites Directory

Your sites live in the frappe-bench/sites directory. This directory also houses several other files and directories integral to the operation of Empress.

apps.txt

The apps.txt file houses a list of Empress apps. An app must be listed here before it can be installed on a site. When you run the bench get-app or bench new-app command, the app is automatically added to the list.

common_site_config.json

This file is used to store configurations common to all sites. For example, you might want to set certain security parameters or default settings across all your sites.

assets

The assets directory houses client-side files like JavaScript (.js), Cascading Style Sheets (.css), and image files. It is auto-generated with the bench build command and served by Nginx in production.

Creating a New Site

To create a new site, run the following command from the frappe-bench directory:

$ bench new-site mysite.local

This command will create a new directory, mysite.local, under the sites directory.

Directory Structure

Each site has a specific directory structure:

sites/mysite.local
├── locks
├── private
│   ├── backups
│   └── files
├── public
│   └── files
├── site_config.json
└── task-logs

locks

This directory is used by the scheduler to synchronize jobs using the file locking concept.

private

The private directory stores files requiring authentication for access. It contains private files and backups.

public

The public directory houses publicly accessible files.

site_config.json

This file stores site-specific configuration.

Site Config

The site_config.json file in every site directory is used to store site-specific configuration. The values are available in the frappe.conf local variable as a dictionary.

Site Resolution

When responding to an HTTP request, the system automatically selects a site based on the Host or X-Empress-Site-Name header in the HTTP request.

You can also force the development server to serve a specific site with the following command:

bench --site mysite.local serve

Setting a Site as the Current Site

Set a site as the default site with the following command:

bench use mysite.local

After running this command, you can run site-specific commands without the --site parameter.

For instance, instead of running:

bench --site mysite.local migrate

You can just run:

bench migrate

Conclusion

Understanding Empress’ Sites feature is crucial for developers looking to leverage Empress’ multi-tenancy capabilities effectively. This knowledge will aid in the successful development, customization, and deployment of business solutions tailored to your specific needs. With this understanding, you can now manage and operate multiple sites, each with its own configurations and database, efficiently and effectively.