DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on

How to host api and frontend sepaparetly while using the same domain ??

I have express API repository which is currently hosted in Heroku along with its documentation site written in ejs.

But now I'm planning on separating the docs website with gatsby and moving it into another repo and hosting it on Netlify while the API service still remains in Heroku.

Here is the end goal :

//example domain: example.com

"/" 
// example.com/ : serves the docs website.(Netlify)

"/api"
// example.com/api : serves the API services. (Heroku)
Enter fullscreen mode Exit fullscreen mode

Can someone help me with how to implement this in the actual application? I am not very familiar with separating hostings while using the same domain.

Top comments (6)

Collapse
 
leonardosnt profile image
Leonardo Santos

I think the easiest way would be to "move" your domain to Netlify and use it's proxy feature to proxy the API requests to Heroku. You could also use a subdomain for the API, instead of using the proxy.

Collapse
 
rocktimsaikia profile image
Rocktim Saikia

Thanks for the response. I looked at the docs and that seems to be the solution. Even tho I have not tried it yet. I Will let you know if I can get it to work.
Anyway, Thank you very much 🚀
Can I reach out to you if I need any further help with this topic?

Collapse
 
leonardosnt profile image
Leonardo Santos

Sure. There's an email on my GitHub profile if you need.

Thread Thread
 
rocktimsaikia profile image
Rocktim Saikia

Great :)

Collapse
 
cavingayle profile image
Cavin Gayle

Thanks so much man!

Collapse
 
rocktimsaikia profile image
Rocktim Saikia

thanks for the response 🦄. I really didn't know much about proxies. But after this issue I read a lot of articles on proxies and finally it's making sense. Anyway thanks for these resources :)