Allow users to add custom domain name

Hey guys,

I’m building a web app (to be deployed on Netlify) that offers users the possibility of connecting their own custom domain that will redirect to their profile page.

So: customdomain.com => myapp.com/profile/userId

I’ve researched a lot about how to accomplish this but ended up with very fragmented pieces of information - and would like to ask for your help to guide me through what needs to be done.

WHAT I KNOW

  1. I can ask the user to create a CNAME record that points his www.customdomain.com to www.myapp.com. However, to accomplish this with his naked domain, an A record pointing to my (static, dedicated) IP address would be necessary.

  2. I need some custom host server logic to redirect the visitor to the correct profile page.

WHAT I NEED TO KNOW

  1. Where do I create this server logic? Do I write an AWS Lambda function here on Netlify?

  2. How would this function be…? In order to find out which profile to open I would have to scan my database in order to find the user that matches the incoming domain… right?

  3. What about SSL? I don’t need to worry about it, right? If the user has it, then redirects will work through HTTPS… if he doesn’t, through HTTP. Right?

Thanks a lot!

Hiya @patrickneuhaus and welcome to our community!

That’s a kind of challenging use case for you to support. Works fine in our system but you’ll spend Some Effort helping your customers debug their custom domains’ DNS setups, so it isn’t likely to be a very great customer experience.

What I’d suggest instead is setting up a subdomain for each user - something like “bob.yourapp.com” for bob, and so forth. Then YOU control the DNS, and we have a setting called “wildcard domains” at the Pro account level that will automatically serve your website to the hostname pattern *.yourapp.com. Then, you’d write the custom logic to handle the hostname and get the userId from it. If you insisted on a 1:1 mapping of hostname<->username, no calculation would be needed - and that’s what many customers of ours who use that feature do - using only clientside logic, to make api requests like this from the webpage:

https://theirapi.com/user/lookup/<theirhostname>

There are dozens of ways you could accomplish similar, of course, but taking DNS debugging out of the loop is likely to work way better for you as a service provider.

Note that if you provide netlify as a paid service to your customers, we intend for you to have at least a Pro (paid) team, but if you need the wildcard domain feature you’ll want that anyway.