For better performance, we wish to separate the rendering from api calls for data, and hence we want to have api's being served from a different server than the one rendering pages.
Keep in mind that MERN has just one server which handles both the web rendering and the API. It just does a really good job at separating the code.
So if you use a different API with BASE_URL, you'll probably want to gut this from your server.js:
app.use('/api', posts);
IMO MERN should move to different processes for the web tier and API tier. I think react-redux-universal-hot-example is a good example of this.
@sandeep & @sudb thought for sure you where talking about Cross-origin resource sharing (CORS) but sounds like you would be using same server domain correct?
Sandeep Panda
co-founder, Hashnode
If you want to serve data from a different server, you can just change the base url. This can be done by passing env variable
BASE_URLwhile starting the server. Take a look at this line.Does that answer your question?