DEV Community

Cover image for Integrating Netlify Frontend with External Backend Using Custom DNS Configuration.
Chidiebere Chukwudi
Chidiebere Chukwudi

Posted on

3

Integrating Netlify Frontend with External Backend Using Custom DNS Configuration.

Hi there πŸ‘‹, I put this piece together because this was me trying to host a frontend project on Netlify then host the backend on a different platform while using a primary domain for the FE (frontendapp.com) and a subdomain for backend API (backend.frontendapp.com)--Remember I said that backend is hosted on another platform too!

Please read on...πŸ˜„

When you deploy an app on Netlify, Netlify generates a custom URL that you can use, e.g., gibberish-gibberish.netlify.com... Netlify also allows you to attach a 'real' domain to this custom domain so your frontend app is exposed to a primary domain.

For your attached primary domain to work properly, you will have to point to Netlify DNS in the custom nameservers section of the primary domain account, in my case, Namecheap.

Now, if I do this (point my DNS to Netlify), my subdomain (backend domain) will be affected. I mean, it will not work because my backend is hosted on another hosting platform.

So we have a problem: FE (frontend) URL works but backend doesn't work because using Netlify DNS as a nameserver for my primary domain will also affect the subdomain too.

You want to ask: why not host the backend on Netlify? Netlify only hosts static files and on top of that, my backend is PHP/Laravel. I hope we are getting somewhere πŸ‘€? Walk with me.

So how did I tackle this issue? It's simple. I switched to using the basic DNS config for my primary domain.

Let me explain in detail....

Configuring DNS For The Frontend

So in my DNS record settings via the advanced section, I added an ALIAS Record and set the host to @ then pointed the record to Netlify's load balancer which is apex-loadbalancer.netlify.com
Netlify's doc reference

External DNS CONFIGURATION

One more thing,
After the domain system for the configuration was properly propagated, I got this error:

default netlify error page

Site Not Found. This in itself is good news. You know why? It means that the domain configuration works but it happened that I still had an old Netlify DNS setup. So the solution will be to delete the former DNS entries from my Netlify account so the external DNS configuration can work.

Configuring DNS Record for Backend

For our backend which is a subdomain for the API deployment on another hosting platform, I created some DNS records for that too.
I set the Record type to A record then set host as subdomain name (e.g., backend) let it point to the platform's IP address.

backend dns record setup

With the following, I was good.

Summary

Now I have my FE hosted on Netlify with some perks like auto deployment, GitHub PR preview URLs, etc., which uses the primary domain (e.g., frontendapp.com) while I conveniently have my API on another platform that uses a subdomain (backend.frontendapp.com). All managed with the DNS configurations mentioned above.

Thanks for reading through. If you do have any questions, do let me know.

Between, I have an open source app I am maintaining with my friends, whatcompanystack.com. Where we are trying to see how we can contribute our quota to the African tech startup ecosystem. whatcompanystack.com lists African startups and their tech stacks. You can use this to get insight into what tech stacks some startups use, etc. It is opensource. You should take a look.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (4)

Collapse
 
augusthottie profile image
augusthottie β€’

i'm glad i walked with you🀭

Collapse
 
jovialcore profile image
Chidiebere Chukwudi β€’

haha. Thanks augusthottie for reading

Collapse
 
fejirogospel profile image
Fejiro Gospel β€’

Nice read

Collapse
 
jovialcore profile image
Chidiebere Chukwudi β€’

Super thanks chief Fejiro

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay