DEV Community

loading...

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

rocktimsaikia profile image Rocktim Saikia ・1 min read

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.

Discussion (7)

pic
Editor guide
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 Author

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
Collapse
cavingayle profile image
Cavin Gayle

Thanks so much man!

Collapse
eruizdechavez profile image
Erick Ruiz de Chavez

In the specific case of Netlify, @leonardosnt already gave you the answer.

In a more general way, what you need to do is called reverse proxy, and it can be easily done with Apache and nginx web servers. It can also be implemented with your own flavor of programming language, to put an example, Redbird is an excellent reverse proxy module for Node.js.

Collapse
rocktimsaikia profile image
Rocktim Saikia Author

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 :)