TODO: setup SSL.
This is a quick guide on how to setup domain and infinite subdomains, in a case where, for example, you may have one subdomain for each client.
Starting from this http://stackoverflow.com/a/39646701
Unfortunately, ALIAS records are not used by Gandi, and A records are not available for use with Heroku because Heroku does not use fixed IP addresses. So we have to use www.mydomain.com
as base url instead of mydomain.com
and set up a redirect from the root domain to the www.
version.
through their CLI (because the internet says their web interface is broken, I don't know if it's accurate), type:
heroku domains:add mydomain.com --app my-app
and
heroku domains:add *.mydomain.com --app my-app
-
Use the Gandi default DNS servers
-
Edit the zone file to be:
@ 10800 IN A 217.70.184.38 * 10800 IN CNAME wildcard.mydomain.com.herokudns.com. www 10800 IN CNAME mydomain.com.herokudns.com.
Note that the trailing . is required
-
Set web forwarding for the domain:
The type of forwarding will be 'direct (permanent)', leave the subdomain blank, and set the forwarding address as
www.mydomain.com
Using Node.js and Express, create a middleware that checks for the subdomains
app.use(function(req, res, next) {
var domains = req.subdomains;
if (/* condition */) {
// your code
req.url = '/something' + req.url;
}
else {
// your code
return res.redirect(somewhere);
}
next();
});
Now Gandi.net supports ALIAS so it could be done simpler, like this:
And in the heroku, you must add only the bare domain and use the given dns (
stormy-squirrel-xe57il0fhyuauzta3noapg1h.herokudns.com.
)