3

Is it possible to use the same nodeJS server for two/three different domains (aliases)? (I don't want to redirect my users. I want them to see the exact URL they typed in the address bar. However, all three domains are exactly the same!)

I want my users to be logged in on all three domains at the same time, in order to avoid any confusion.

What is the simplest way to do this and avoid cross-domain issues?

Thanks!

Emilio
  • 1,314
  • 2
  • 15
  • 39
  • If you are using a subdomain based website naming system, then you can tie the login cookie to the top level domain. This way the user is logged in simultaneously into all 3 websites – TheChetan Apr 17 '18 at 19:04
  • @TheChetan currently all three domains are different such as: elgato.com lechat.com thecat.com Thanks! – Emilio Apr 17 '18 at 19:18
  • @Emilio, if my answer helped, I'd appreciate if you'd accept and award the bounty; if you do nothing within the next 2 hours, then at least half of the bounty will be lost forever. – cnst Apr 18 '18 at 17:53

3 Answers3

3

If you mean that all domains will serve the same nodejs app then Yes you can do that.

but if each domain should open a different application then you must have a reverse proxy running on the server to handle and manage the sites/vhosts.

You may install nginx and use it as reverse proxy server or look for http-proxy a library for nodejs.

If you would like to manage the vhosts in your app you can look for vhost middleware for nodejs and use it

2

Choose one of:

Use some other server (like nginx) as a reverse proxy.

Use node-http-proxy as a reverse proxy.

Use the vhost middleware if each domain can be served from the same Connect/Express codebase and node.js instance.

  • There's no danger with cookies? So when a user logs in on one of the domains, he is automatically logged in on all domains? – Emilio Mar 11 '18 at 17:09
2

This is a very broad question. Moreover, it is generally a pretty bad idea, SEO-wise, to have multiple independent domains that each serve the same content.

Logging in is generally either done through Cookies, or through extra parameters in the URL. Cookies are always domain-specific, for obvious security reasons. If you want to ensure folks will be logged in to all the domains at once, you can create an internal purpose-driven domain to handle authentication (without such domain showing in URL bar, and only being used for HTTP redirects, effectively); such domain will store the login state for all the rest, and the rest would pick up the login state through such purpose-driven domain (through HTTP redirects).

In general, however, this sounds like too much trouble. Consider that, perhaps, some users specifically want to use different domains for different accounts, so, you'll effectively break their usage if you mandate that a single login be used for all of them. And, back to the original point, doing this is pretty bad for SEO, so, just don't do it.

cnst
  • 25,870
  • 6
  • 90
  • 122
  • Let's say I have three domains. thecat.com, elgato.com , lechat.com . In fact all three websites are the same. However, I want my Spanish users to see the URL in Spanish, my French users to see the URL in French and my English users to see the URL in English. // Not sure how it's bad for my SEO, if I only allow Google to see the French content on the French URL, the English content on the English URL and the Spanish content on the Spanish URL. – Emilio Apr 11 '18 at 02:30
  • Right now the website is set up so that when users switch language, they stay on the same URL. Maybe I should only allow them to see the English content on the English URL, the Spanish content on the Spanish URL, etc. What do you think? – Emilio Apr 11 '18 at 02:35
  • @Emilio, well, yeah, then it's not the same content. Allowing to see the different version on each domain makes sense. I'm not too sure if a single login is warranted or not; this kinda depends on how integrated the business is. – cnst Apr 11 '18 at 20:09