1

How can I create subdomains dynamically for each newly registered user in my Node / Angular app? I have come across several posts that suggest using an nginx server. Is there a way to accomplish the same thing but without using nginx?

Edit: I want the user to see userA.mydomain.com in their browser. I also want them later on (after registration) to navigate to such a URL and land on their own customized page.

In addition, I want the user to be able to map this subdomain userA.mydomain.com to their own custom subdomain such as course.userwebsite.com

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • can you add more specifics of your use case? do you want a user to see something like userA.mydomain.com in their browser? do you want them to later on (after registration) navigate to such a URL and land on their own customized page? etc etc? – Sergey Rudenko Dec 31 '19 at 06:02
  • @SergeyRudenko: yes, you are exactly right, I want the user to see userA.mydomain.com in their browser (after registration). I also want them later on (after registration) navigate to such a URL and land on their own customized page. In addition, I want the user to be able to map this subdomain userA.mydomain.com to their own custom subdomain such as course.userwebsite.com – Manvendra Singh Dec 31 '19 at 06:15
  • You can rewrite a url, but you still need to purchase a domain name and register subdomains to it. That's nothing to do with Angular or nginx. For example, http://userwebsite.com seems to be available for purchase – OneCricketeer Dec 31 '19 at 06:24
  • @cricket_007 thanks for replying. I can purchase a domain and create a wildcard subdomain (*) using cpanel and handle all wildcard subdomains with a library like https://github.com/patmood/wildcard-subdomains/ so that userA.mydomain.com is resolved as mydomain.com/sub/userA, which I can handle easily. I am not sure how I can make this change userA.mydomain.com reflect in the user's address bar in their browser? Will a URL rewrite work? – Manvendra Singh Dec 31 '19 at 06:31
  • @cricket_007 i used userwebsite.com as an example. The actual website could be different – Manvendra Singh Dec 31 '19 at 06:33
  • 1
    I think that's where nginx (IIS, HAProxy, etc) is required. The server is responsible for the url rewrite, not the Angular client. But my point is that that address you chose could be owned by someone else, so you probably shouldn't be generating it based on some user criteria – OneCricketeer Dec 31 '19 at 06:33
  • Related answer https://stackoverflow.com/questions/13446030/rewrite-url-path-using-node-js – OneCricketeer Dec 31 '19 at 06:36
  • @cricket_007 I checkout out the answer you linked to. thanks. The accept answer over there suggests using a middleware function and there is no mention of nginx. As per your previous comment, there is no escaping nginx. Could you please clarify? – Manvendra Singh Dec 31 '19 at 06:46
  • 1
    Nodejs operates as a server. It can rewrite urls from the request. You get increased performance by using nginx or the other options because they serve static files and handle additional http features like reverse proxying and load balancing because you should be running multiple instances of your applications for fault tolerance – OneCricketeer Dec 31 '19 at 12:52

0 Answers0