anishlushte07 / multi-tenant-application Goto Github PK
View Code? Open in Web Editor NEWMulti tenant application using NodeJs, express and mysql
License: Apache License 2.0
Multi tenant application using NodeJs, express and mysql
License: Apache License 2.0
I like to use this in my projects. Please update the license so that I can understand limitations
Example:
Minio Released under apache 2.0 - https://github.com/minio/minio/blob/master/LICENSE
Instead of query params
we can get from session - req.user.clientId
as the tenant db connection details written in .env file,
adding tenant dynamically requires restart
I can achieve graceful restart using https://gist.github.com/manjeshpv/60924207056773954f6a346db6cc5249
is there any possibilities to dynamically bootup sequelize models inside running memory
multi-tenant-application/server/app.js
Line 17 in 2ce643a
so migrations will run on tenant create api, instead of connection details .env and manually running migrations
multi-tenant-application/sample.env
Line 8 in 2ce643a
with this repo, I can manually provision app for multiple tenants,
automating provisioning help to scale business
Customer signup with email id and password(CommonDb.users id:1 email: [email protected] )
POST /api//users
const mainDomain = 'tenantapp.com';
const linodeIp = '120.120.120.120'
// either we can use this function of we can keep *.tenantapp.com -> 120.120.120.120
// linode centos server with ip 120.120.120.120
const createDNS = (subdomain) => {
rp({
url: `https://api.digitalocean.com/api/domains/${mainDomain}/A`,
method: POST',
body: { subdomain, ip: linodeIp }
})
}
export async function create(req, res, next) {
const user = await CommonDb.User.create({ email: req.body.email }); // id:1
const domain = req.body.email.split('@')[1];
const subdomain = domain.split('.')[0];
const project = 'nps_feedback';
const connectionString = await MySQLApi.createDb(`${subdomain}_${project}`);
const client = await CommonDb.Client.create({ user_id: user.id, name: subdomain, connectionString });
await SequelizeApi.migrateDb(connectionString);
await SequelizeApi.seedDb(connectionString);
// all subdomains pointing to one machine as wildcard dns entry
user.update({ client_id: client.id });
res.json({ message: 'Signup successful, Provisioning done from http://${subdomain}.${mainDomain}'})
}
domain: flipkart.tenantapp.com
1. dbinfo = DB Creation Script
2. dbId = saveDbInfoToCommonDbClientsTable(dbInfo)
3.
mailtrain version 1 focussed on building email campaign manager
v2(https://github.com/Mailtrain-org/mailtrain/tree/development) focussed on making multi tenancy,
Is there any way without changing the code of existing nodejs app, we can add multi tenancy to a nodejs/express app already built
Benefits
Current Challenges while setup
With above 3 steps we can automate setup process,
Expectation is run migration of another existing nodejs application so we can add a add a field sequelizerc
in client(tenant
) table
sequelizerc: DataTypes.JSON
above field will be updated with
multi-tenant-application/sequelizerc-tenant2.json
Lines 1 to 5 in 2ce643a
NOTE: In other words, if we make a provisioning tool, then it will help developers to focus on domain, Automatic Provisioning tool will automate tenant signup process
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.