How can the Dynamic Sub domain routing feature be implementing in NextJS?
Example: If a user comes with username abc
in site xyz
then he can access his
site on abc.xyz.com
Also, if the user have abc.com
domain then he can point abc.com
to abc.xyz.com
So in future if someone opens abc.com
then abc.xyz.com
is served. And in URL
also the abc.com
is shown.
I have investigated few plugin in NPM like vhost and wildcard-subdomains but not sure that is right way to take on this issue.
The vhost requires changes in system hosts
in local system and wildcard-subdomain solves the issue purely with routing.
The Local System Setting I have customized Server.js With Code Which Works Temporarily, but does't seems to be a solution which can be used in production :
Server.js
...
if (pathname === "/demo.demo.com") {
app.render(req, res, "/demo.demo.com", query);
}
...
And in _app.js
static async getInitialProps(appArgument) {
...
return {
...
renderFrom: "demo.demo.com"
};
}
Also in my host I have demo.demo.com
point to localhost
.
The site works for me in demo.demo.com:3000
but how to generalise it in production scenarios
with Database and CNAME
Records and add/change CNAME Record automatically with User Action.