Subdomain routing for Saas

Hi, I’m trying to make a SaaS multi-tenancy project in NodeJS
A project that allow to autogenerate subdomains base on a business creation in database mysql, and then each subdomain filter the data base on that business created.

I’m was reading about this and others topics, but unfortunetly there are no more context about how this can be implemented using Wappler.


The next part is the that section that propably every Wappler consumer can do with some previous experience, I’m mean, basic things, because what I requesting for me is not basic, but useful for everyone that will start with SaaS.

Main domain: business.com
A Superadmin create an account for this business, then, create a user admin with propper permissions to only manage this business account and all the info relate to this. At this point every business have a unique ID “business_id”, this is the column that allow to filter all info for this business, so, something like this:

The busines info is: Business One
The suggest subdomain: businessone
Full URL: businessone.business.com
(mysql in table ‘business_name’) business_id: 1

At this point I have all the configuration complete to generate the propper info for each subdomain, or at least that is what I believe.

Right now the project is in docker using Wappler just for make things easly, but in production, for now the idea is to config a nodejs server in cloud hosting without docker, because I’m not sure about how to deal with docker.

How to configure routes in Wappler to works as subdomains and not only for path in domain?.
How to filter data base on subdomain with the help of “business_id” already created?.
How to test the above in local using the current docker that Wappler provide?

Please, someone with previous experience that already made SaaS with subdomain that can share with us how to do this, I’m not programmer but Wappler in some manner obligade us to learn programming (for me that’s cool actually, I’ve learned a lot.) but things like this are complicated to understand at first.

Please I’m not asking a project ready to use as an example (to be honest would be great considering that most of the questions in forums lacks of context and becomes unnusable for us because sometimes we do not understand with the solution that some user gave, how they ended up solving the problem.) but, it will be great if is maybe possible to provide some guide to learn or steps to how to do it.

Thanks, I really hope someone can help.

@wappler_ambassadors

1 Like

Create a test Server Action, and put there:

Set Value env = {{$_ENV}}
Set Value server = {{$_SERVER}}

Try to find the current (sub)domain in one of those variables, so there you have how to find the current subdomain being accessed.

On your DNS provider you have to make a wildcard DNS entry (like *.example.com) to point to your server’s IP address.

If you click on Globals, these are Steps that run on every page. There, check the current subdomain (from variable like $_SERVER.something), do a database query to get the business_id from the subdomain string


Now you have access to business_id on every page

2 Likes

Use server connect for redirect to domain?