React.js with Node.js Rest API

Should I include a Reactjs application in the same application as my REST API?

I am new to Reactjs. I have created several standalone Node REST APIs. I am creating a React app, an Android app, and an iOS app (so the REST API must serve all three apps). I was wondering what the convention dictates when building the Node API.

There are two options, as I see it ...

1) I could create one large application that covers the REST API and React App. This app will serve all API calls from mobile apps and responsive / web apps. It will also serve all views, such as HTML, CSS, etc.

OR

2) I could create two small applications. One of them will serve as a React application with presentation templates with a separate (lighter) Node server. In the second application there would be no views. It just works as a JSON API to serve all three applications.

+5
source share
2 answers

I would recommend using an isomorphic application. Check out this boiler plate: react-redux-universal-hot-example .

You can use two ports in your project: one for rendering your reactive views (I prefer server-side rendering to provide faster web rendering), and the other for apis and web sockets.

Your mobile applications can also use api / ws server for RESTful services.

+2
source

I recommend creating a single application for the interface and backend. Once scaling becomes a problem, separating these two factors will be more reasonable, because you need the contents of the external interface to serve from the CDN.

But for something small, separating the interface and the backend, you will need to start two separate servers and deal with CORS: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

0
source

All Articles