2

I've been getting stuck on how to deploy my React SPA front end on Netlify and my NodeJS Express api backend on Heroku using the same domain name. The domain is a Google Domain and currently the Netlify front end works just fine at www.MyDomain.com.

What I've been trying to get set up is a way to have something like api.MyDomain.com/api/v1/endpoint be able to call the backend service hosted on Heroku. I've tried setting up subdomains via Google Domains for api.MyDomain.com and Netlify redirects to api.myDomain.com whenever accessing any routes like www.MyDomain.com/api/* but I haven't been able to make any progress.

Is it possible to host a single page Netlify front end and an express api heroku backend on the same domain? If anyone has experience with this combination that could point me in the right direction that would be awesome. Thank you.

1 Answers1

0

As you only have trouble to add the backend on a subdomain, here is what you should do:

1 - Add the domain with the subdomain to the Heroku app:

In the Heroku dashboard, go to the app's settings. Click "Add domain" and type the domain with the subdomain you want (e.g: api.yourcustomdomain.com)

You'll then be prompted the DNS target:

enter image description here

2 - Add the DNS target to Google domain

In the DNS manager of your domain in Google domains, simply add a CNAME record with the DNS target, it should looks like something like this:

enter image description here

Allow some time for the DNS to propagate and it should work !

Clément
  • 98
  • 2
  • 6
  • Hi Clément, I've followed your guidelines, but 12 hours later, Heroku still can't find the DNS. Should I write www.server.myapp.com or server.myapp.com in Heroku's domain name input? Maybe the error comes from here? I've created a thread https://stackoverflow.com/questions/67685371/heroku-unable-to-resolve-dns-for-server feel free to answer there if you have time to do so. I'd very much appreciate your advice on the matter :)! – DoneDeal0 May 25 '21 at 19:43