(shortened to fit char lmit)
I am currently working on a project where I need to support multiple tenants (subdomains) using a single instance of Strapi. The goal is to have a shared codebase while dynamically handling requests based on the subdomain, each pointing to a different database and file storage.
Here are the specifics of what I’m trying to achieve:
Each subdomain (e.g., 4000.krusty.bsgn.cc, 4001.krusty.bsgn.cc) should use a different MySQL database. The database name can be constructed from the subdomain and a base name (e.g., krusty_4000, krusty_4001).
Each subdomain should have its own file storage directory. This directory path can also be constructed from the subdomain and a base path.
The application should dynamically allow CORS for each subdomain. For example, https://4000.krusty.bsgn.cc/ should be allowed for the subdomain 4000.krusty.bsgn.cc.
Ideally, I would like to avoid running multiple instances of Strapi for each tenant to conserve resources. Instead, I aim to handle this dynamically within a single Strapi instance.
Qs:
How can I properly configure Strapi to dynamically switch databases and file storage paths based on the incoming subdomain request?
Are there any best practices or existing plugins/middleware that can facilitate a multi-tenant architecture with a single Strapi instance?
So far, I run an instance (using pm2) for each client (tenant). But tha’t not optimal for scaling my client base, because every instance takes hundrend of MBs of RAM, so for example on a 8GB machine, I’d accomodate max 40 clients (200MB/instance).
In a similar multi-tenant architecture in PHP, I decide what DB and storage to use on every incoming request. I understand that in Node environment, that’s going to be different - but is there a way? Does Strapi count with such use?
Thank you in advance for your help! Jakub Mirejovsky
This topic has been created from a Discord post (1254852895237734584) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord