Custom domain

@sid which part? Give me a specific question and I’ll do my best to answer.

@mebeingken Thanks for the reply.
I don’t know very much about how the server-domain configuration works.
Have started working on VPS only in the last few months and it has been a lot of learning.

One of our client applications needed to run on custom sub-domains, just like your setup.
For that, we used caprover, which would deploy multiple instances of the same app from Git, under each pre-defined subdomain.
So its neither automatic, nor a single app.

What I would like to know is how you have setup the app to run on dynamic subdomains from single code base?

In Globals (through a library flow) I check to see if $_SESSION.tenant_id has been set. If it has, do nothing. If not, then lookup the tenant in the database using $_SERVER.HTTP_HOST. Then set the tenant_id to the session variable.

In all db tables (except for all global tables) there is a required column of tenant_id that has a foreign key back to the tenant table.

All db actions whether query, insert, update, delete, custom include the tenant_id bound to the session variable.

I do understand the tenant id logic, but I don’t get how say user1.mealpro.com & user2.mealpro.com both point to the same application.
I helped a client on a project where he created a SaaS with subscriptions and similar tenant_id setup. But it all happens on the same domain.
I have been using shared server with cPanel in the past, and have just started using and learning about VPS (Droplets mostly), and I still don’t get the above sub-domain concept.

@mebeingken row-level security is great for isolating different tenants in the same database. I don’t know if mysql/mariadb implement it but PG does for sure. That way you remove the burden and repetitive task of filtering every single query on the app side.

Maybe for future projects you might want to consider it.

2 Likes

Ya, everytime I start a new one I think I’ll either move to that, or different db logins, or even complete db segmentation, but something always pulls me back to this…probably familiarity, but I can’t remember the calculus that goes into my decision. What I haven’t done is what you suggest and use PG. I’ll add that into the mix next time!

1 Like

A domain just points to a server, and the server decides what should load. So all the domains just point to the same virtual host. In this case, it is apache that hands off to Node. We have it on the roadmap though to switch to something like https://caddyserver.com/ instead of apache, if for nothing else than to eliminate the certificate provisioning.

Most of that just went over my head. :sweat_smile:
Looked at caddyserver and it looks interesting, although again, most of it went over my head.

To simplify my question:
I create a droplet & deploy using Wappler’s deploy option. The URL is set in target settings.
What do I setup on the droplet to allow the multi-domain stuff?
Or is this completely incorrect?

To configure this, the DB connection in globals needs to be configured with dynamic user credentials?
How would that even work? I understand that environment variables can be used in DB connection, but what to use here?