DEV Community

KaMeHaMeHA
KaMeHaMeHA

Posted on

How to allow users to add their own custom domains?

I am using node.js and I want to give my users the ability to add their own custom domains. For example, my app is hosted on DigitalOcean with the domain ‘https://app.com’ and the user, say, John, the page is ‘https://app.com/john’ Now I want my user, John, to be able to add his own domain ‘www.john.com’ so that it displays ‘https://app.com/john’ site

Top comments (1)

Collapse
 
carterbryden profile image
Carter Bryden

Generally you need:

  1. Something to generate/renew/manage SSL certs for each custom domain (and to handle random events like certificates being revoked by a certificate authority)
  2. Something to route custom domain traffic to your app
  3. Something to filter out requests for custom domains that your app hasn't approved
  4. Some way for your app to know what to do with requests for each custom domain (load specific content, for instance)
  5. Maybe handle distributed routing, if your app is globally distributed or on something like vercel, firebase, AWS lambda, etc. - this can be especially tricky to build and manage well.

If you want to build and manage this yourself, your best bet is probably Caddy Server, which can handle some of this out of the box, and all of it with some effort (and learning curve).

Another easy and affordable way to do this is with approximated.app, which will handle all of this for you for around what you'd spend doing it yourself. Note: I'm the founder, so I'm both biased and open to questions (about any of it) if you've got any!