Using Node.js/Express I have a REST API with multiple isomorphic/universal applications which consume this API.
I would like to allow users to have their own subdomain and this to happen dynamically as they sign up.
From what I've researched the best way to do this is to point a wildcard record to the isomorphic/universal application servers and have some logic there which interprets requests looking for a subdomain and serves up the appropriate pages. This I assume needs to sit in front of the application and happen for every request to the server.
Would this be the best way to approach this problem? Is there an alternative way?
Are there going to be any potential issues with scalability?
I would then like to allow users to have a custom domain. Tumblr and other services provide a similar feature where they allow you to point a CNAME record to the users subdomain. I have been unable to find much information on how this works.
What is the best way to allow users to use a custom domain for their area within an application?
The subdomain option allows you to choose a subdomain of totalwebsiteprotection.com (mycompany.totalwebsiteprotection.com). No extra setup is required! 2. For even more control, the custom domain option allows you to use any domain you like (backups.mycompany.com).
Would this be the best way to approach this problem? Is there an alternative way?
Are there going to be any potential issues with scalability?
What you described with the wildcard DNS is the best way and you won't encounter any scalability issues caused by that. The alternative is to use a DNS host that has an API, such as Route 53, and dynamically add a subdomain to it for each user. That has several disadvantages over the wildcard though. It could become a pain to maintain, it could take a while for new DNS records to propagate, and you may quickly hit limits (On Route 53 you need to request a limit increase to go above 500 hosted zones per AWS account).
What is the best way to allow users to use a custom domain for their area within an application?
The same way you have logic to check the subdomain (checking the HTTP Host header). When a request comes in you can check the Host header and determine which user the domain belongs to (whether it is a subdomain or a full custom domain); as long as they've told you what their domain(s) are. Adding the CNAME is their responsibility (though you can give them guidance, obviously).
If you support HTTPS, you will only be able to do that on devices that support SNI. You can get a wildcard cert for the subdomains, but you will either need the domain owners to upload a PEM file or get their permission and use something like Lets Encrypt's api with the webroot domain verification check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With