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

twitter logo github logo ・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

twitter logo DISCUSS (9)
markdown guide
 

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!

 

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.

 
 

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

 

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

 

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

 

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

 

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

 

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

Classic DEV Post from Oct 3

Let's Talk About Passion

Too many articles offer misguided advice on passion. Let's set the record straight. Here's a more nuanced view on passion, which I hope will be encouraging in its own right too.

ADONIS SIMO profile image
Python/Js developer. Learning GoLang