Setting custom subdomain on Heroku app - heroku

I want to set a custom subdomain to a Heroku application. The top-level domain is associated to a different application outside Heroku.
I've read Heroku's custom domain documentation, but I'm still unclear on how to approach this.
From the documentation, it gives off the impression that I must set the top-level domain to the application if I want to set the custom subdomain. Is this the case?
At the moment I've set a CNAME record pointing to the Heroku app in question:
subdomain.domain.com => subdomain.herokuapp.com
Is this sufficient? Or would I also need to set the top-level domain? If so, would it conflict with it's association to the different application?
Just want to make sure I'm setting it correctly, since the DNS propagation takes a while. Thanks!

That's fine. You only need to set the top-level domain to the app if you want the top-level domain to resolve to the app.

Related

Accessing an app via heroku domain when it's set to a custom domain

I have an app with a custom domain that I'm letting retire.
I'd like to keep the custom domain until it expires but give people the ability to access the app via the heroku domain already so they can get used to it, but when I go to the address specified in my app, it says no app is found.
Is it invisible because of the custom domain? Is there another way to expose the heroku domain to the world?
Thanks in advance :)

Multi domain session cookie

I have 2 Asp.Net Core 2.2 applications and I want to share session between them. I've set up session in a SQL database and both connect ok. They are on different sub domains. I understand that I can set the Cookie.Domain the startup file, which would solve the problem at a basic level, so each application would create the cookie such that it can be accessed. e.g.
Domain 1. "www.website.com"
Domain 2. "dashboard.website.com"
At present these sites can't access each others session cookie.
If I set the domain cookie to ".website.com", both should be able to access this.
The problem is that we have multiple domains that use this website, so it could be:
www.domain1.com
dashboard.domain1.com
www.domain2.com
dashboard.domain2.com
www.domain3.com
dashboard.domain3.com
I need to be able to inject the current host name into the startup cookie domain, in order to have it dynamically set, depending on the domain of the active website.
Is this at all possible?
Just to clarify, www.domain1.com does not need to be able to access www.domain2.com.
Only the www. and dashboard. variations of each domain need to be able to connect to each other.
Thanks in advance,
David
To share sessions across applications, you need only follow the directions in the docs. It basically boils down to two things:
You need to persist the data protection keys to a common store that all the apps can access. A UNC path will do, or you can even use something like Azure Key Vault.
You need to set a common application name. Data protection values are segregated by application by default. Setting a custom name, which is then used across all the apps allows them to all access the same set of data.
As far as setting the cookie domain goes. There's no good way to do this by convention. The actual domain name is only available in the context of the request pipeline, which is not available to you in something like Startup (there's no request). Even if you could, it's not reliable anyways. In situations where you have a reverse proxy or, importantly , when hosting in containers, the domain will be localhost, since the actual domain isn't applied directly to the app.
Long and short, your best bet is to use configuration. You can, for example, have environment-specific JSON files like appsettings.Domain1.json, appsettings.Domain2.json, etc. Inside each, you can add a something like:
{
"CookieDomain": ".domain1.com"
}
Then, when you deploy, you set the environment to the appropriate domain, and that config file will be used. In Startup, you'd just do:
services.ConfigureApplicationCookie(o => {
o.Cookie.Domain = Configuration["CookieDomain"];
});

Pointing domain to Heroku application with wildcard

I have an application where users get their own subdomain, like site1.mysite.example. I would like to allow users to register a custom domain that they can point to to their sub domain but I'm having trouble figuring how to configure Heroku and my DNS settings to allow this.
In my DNS settings for my domain I have a CNAME record setup like so:
Host = *
Value = sites.mysite.example
The value here is an app I have running which will translate the subdomain (site1.mysite.example) to figure out which site to load.
I have a CNAME for mysite.com which points to Heroku's DNS site:
Host = sites.mysite.example
Value = mysite.example.herokudns.com
On the domain I'm testing with I have a CNAME record setup like this:
Host = docs.othersite.example
Value = site1.mysite.example - this is the subdomain they get on my site
But for some reason this is not working. If I register site1.mysite.example as the custom domain in my application and I run dig site1.mysite.example I get the following:
;; ANSWER SECTION:
docs.othersite.example IN CNAME site1.mysite.example
site1.mysite.example IN CNAME sites.mysite.example
sites.mysite.example IN CNAME mysite.example.herokudns.com.
When I try docs.othersite.example in a browser I get Heroku's There's nothing here, yet. page. So it seems like Heroku is not loading up my application. I am guessing this is because I do not have docs.othersite.example registered as a domain in my Heroku application, but I do not want to have to register every custom domain. Also, I do not own these domains so I could not anyway.
What am I doing wrong here? Any help is much appreciated. I'm happy to post any more info someone needs or clarify anything.
Heroku does support wildcard domains, so in this case you could add *.othersite.example to your Heorku app's custom domains.
If you need to support different root domains (othersite2.example, othersite3.example) for each user, there's no easy way to support that. You'd need use Heroku's Platform API to programmatically manage custom domains.

How to add wildcard to Heroku app without custom domain?

I tried to add wildcard domain to my existing app hosting as mysite.herokuapp.com - without a custom domain. The point is it's my test app and application itself allows end users create apps that would be visible as subdomains.
So I configured custom domain and wildcard for main prod app, now I want it to be done for my dev (test) app - so here I need only wildcard but not custom domain. If I try to do it I have "Can't add an additional Heroku domain." What to do to fix it? Is it even possible? Thanks!
UPDATE I have the official answer from Heroku support. It's impossible, I can only add wildcard domain to my custom domain.

Providing customers with domain aliasing

Currently I have an app which gives my users a custom subdomain.
neat.coolapp.com
However, I want my users to be able to CNAME their personal domain to that website.
ex. hey.neat.com -> neat.coolapp.com
Is this possible on heroku?
Thanks in advance for any insight.
You'll need to add whatever domain the customer wants to use to your application so the correct application on Heroku responds - you could do this either manually (via the heroku control panel) or use the heroku gem within your application to add the domain to your application via some kind of control panel if the customer is able to add their own domains.
In regards to cname's - I would suggest setting up something like proxy.yourwebsite.com as a CNAME to yourapp.heroku.com and then you get your customers to cname their domain to proxy.yourwebsite.com in their DNS config.
When you sign up for Heroku you will get a subdomain like
asdf.heroku.com
If you have a domain like mywebsite.com you can cname mywebsite.com to asdf.heroku.com and you will need to add mywebsite.com to Heroku's custom domain command.
From there I'm not sure, if you wanted to add mywebsite2.com without having to add it using the custom domain command you can try to cname it to mywebsite.com, if you have two domains you can try it out.

Resources