loading...

How to create sub-domain automatically when users register on my SaaS application ?

simo97 profile image ADONIS SIMO ・1 min read

Hi, am currently working on a SaaS product and i will need to create sub-domain on fly as users register on the app. I think this operation is related to the DNS provider or the hosting service, via an API for example. But i don't really know how it work. Looking for some help on this.

thanks

Discussion

pic
Editor guide
Collapse
matthew_collison profile image
Matthew Collison

You wouldn't create the subdomain on the fly, you'd simply use a wildcard subdomain (*.yourwebsite.tld) and point that to your webserver.

Depending on what backend framework you are using, you'd need to ingest the subdomain as a parameter and use the value from that to find the user (or throw a 404, of course)

Hope that helps!

Collapse
simo97 profile image
ADONIS SIMO Author

oww.... that's interesting... i only knew about SSL wildcard certificat... this is sooo cool. Thank it solve my problem, am working with a NGINX + Gunicorn + Django Stack.. i can handle the domain name ingestion without problem... thank you for this.

Collapse
matthew_collison profile image
Matthew Collison

Super welcome - glad it helped!

Collapse
d3sandoval profile image
Daniel Sandoval

Yup! This is essentially what anymessage does to generate the team subdomains. Feel free to checkout the code, if you'd like a node.js example: github.com/d3sandoval/anymessage

Collapse
kosadaz profile image
Kosadaz

Hi Matthew,

Better to have single VM and single db running for each tenant? Or multitenant single db if that the case?

ie. Slack use subdomain with single db or multitenant db?

Collapse
chr314 profile image
Christoforos Aslanov

if you are using cloudflare they have rest api api.cloudflare.com

with simple http requests you can manage your dns records

this way you can have multiple servers

Collapse
simo97 profile image
ADONIS SIMO Author

Ha... I had this kind of solution in mind.. thanks for this. I will check that, it seem to be more suitable concerning security.

Collapse
chr314 profile image
Christoforos Aslanov

yeah cloudflare is great, in the free package they give you tools like waf, ddos protection, cdn, js css optimization etc and your server ip is not exposed to the public because cloudflare works as reverse proxy

Collapse
kalium profile image
kalium.xyz

You can get wildstar certificates for TLS on AWS, if you want to have a secure connection while serving any subdomain.

Collapse
simo97 profile image
ADONIS SIMO Author

yeah thank you, i knew about this type of certificate, i use to get them from GlobalSign.

Collapse
magicmarvman profile image
Marvin

You could easily get them for free from Let‘s Encrypt.

Collapse
ikennaobieze profile image
Paschal Jeremy

You have gotten lots of advice already but I feel an important part is left out - using a load balancer.

You can configure Nginx to handle this then instead of calling Cloudflare API as suggested above, just point the wildcard to Nginx.
From there, you can do whatever you want with the resulting traffic - authenticate it, redirect to another microservice - anything you want.