I'm creating a NextJS project which makes use of wildcard subdomains.
I've set up wildcard subdomains on Vercel, so now each wildcard subdomain points to my main NextJS installation. Within the NextJS app, I'm reading the subdomain name and serving the content accordingly.
So, let's say my wildcard entry is *.example.com
Now, all subdomains, such as roman.example.com
, greek.example.com
, are being served correctly with content coming from my database correctly.
The challenge I'm facing is to map custom domains to each of these subdomains.
For example, if I want myroman.com
to map to roman.example.com
and mygreek.com
to map to greek.example.com
, I'm unable to get it to work.
Say, for example, if in myroman.com
DNS records, if I add a CNAME record pointing to roman.example.com
, and then if I visit myroman.com
, it shows me 404 deployments not found error. Note that something like myroman.com
is a customer's site, and the only thing I can ask a customer is to add a DNS record to map it to a sub-domain. I cannot take control of their domain or anything like that.
You would see that companies like substack offer such custom domain mapping to their customers.
Can you suggest what's the best way to achieve this? I'm okay to change host or anything to make this work.