2

I am developing an application with ExpressJS. And i want to use sub domains on this application.(Virtual subdomains)

Is there any way to interprete this url;

http://customer_name.mysite.com

as

http://mysite.com/customer_name

My current url mapping on cntroller like this;

app.get('/:customer_name/?', function(req, res, next) {
//something functions
});

Thanks in advance

Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
  • I have answered a similar question here: http://stackoverflow.com/questions/5791260/how-can-i-configure-multiple-sub-domains-in-express-js-or-connect-js/23324995#23324995 – bmullan91 Apr 27 '14 at 15:14

3 Answers3

5

I have added wildcard domain on my domain provider(GoDaddy). You can refer here for how to add wildcard domain

And then, i have prepared a middleware that parses url and get subdomain part. Query subdomain text as user that's all.

For getting subdomain, you can refer here. Simply get host name and split it. First one is the subdomain name.

Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
  • Could you give some details on how you did the first part. Did you add A record or CName? – Max Pain Jul 28 '15 at 06:21
  • @MaxPain I have added CNAME record. – Hüseyin BABAL Jul 28 '15 at 06:52
  • So I added a CNAME at Godaddy host name just * and made it points to mycoolapp.parseapp.com, do I need to change anything on parse.com? Right I have the host name set to www.mycoolapp.com. – Max Pain Jul 28 '15 at 11:56
  • When I added the CName record, I am getting this message now when I try to access something like hi.mycoolapp.com Parse App not found We don't seem to have an app at this host name. It might not be configured correctly, or may have moved. – Max Pain Jul 28 '15 at 12:03
3

That's exactly the usecase of the express-subdomains module.

Your require it, tell it the subdomains and all requests on these subdomains are available as prefixes to your routes.

For example

customer_name.mysite.com/route

would be mapped to

mysite.com/customer_name/route

sbugert
  • 345
  • 3
  • 5
  • However, i cannot tell the domain names to express. Since, when a user create an accoutn, also virtual subdomains created. There is no physical subdomain – Hüseyin BABAL Sep 20 '13 at 10:18
1

Nodejs has nothing to do with these stuff. That's what the server is meant to handle with. Node just listens to a port and that's it. It's your job to forward any host to that port. So, I guess you should play with your server setup.

Krasimir
  • 13,306
  • 3
  • 40
  • 55