I am used to working on httpd ( Apache ) which provides a way to configure subdomains which is mapped to a directory. How can I do the same thing in Connect.js/Express.js ? I see that the only thing that I have is routes which I am not sure how I can use to configure sub domains. I have subdomains like m.mysite.com, sync.mysite.com
Can someone help ?
Each domain name can have up to 500 subdomains. You can also add multiple levels of subdomains, such as info.blog.yoursite.com. A subdomain can be up to 255 characters long, but if you have multiple levels in your subdomain, each level can only be 63 characters long.
localhost is not supposed to have any subdomains. To do so violates the approved RFC standards. localhost has an A record and in IPv6 environments, an AAAA record. All other DNS record types, including SOA are forbidden.
Or alternatively you could use vhost
.
Then, create several sites in their own directory and export the express app, eg. /path/to/m/index.js
:
var app = express() /* whatever configuration code */ exports.app = app // There is no need for .listen()
And then handle all requests with the following app:
var vhost = require('vhost'); express() .use(vhost('m.mysite.com', require('/path/to/m').app)) .use(vhost('sync.mysite.com', require('/path/to/sync').app)) .listen(80)
Note that /path/to/m
and /path/to/sync
can be absolute paths (as written above) or relative paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With