admin管理员组文章数量:1400195
So I am creating a multiplatform application using React & Spring (Java)
I want to make the Spring backend a REST webservice that can be called by both a React-Native and a React frontend.
I currently have my project broken up into 3 sub projects: backend (Spring), webapp-frontend (React webapp), mobile-frontend (React native)
My question is on how I should actually serve the React webapp frontend. I will have the webservice on a server somewhere so that the React code can hit it to make API calls, but as far as serving the React webapp would it be better to do serve it with the same backend server or would it be better to make a seperate frontend server with something like express? Also, are there any other alternatives?
So I am creating a multiplatform application using React & Spring (Java)
I want to make the Spring backend a REST webservice that can be called by both a React-Native and a React frontend.
I currently have my project broken up into 3 sub projects: backend (Spring), webapp-frontend (React webapp), mobile-frontend (React native)
My question is on how I should actually serve the React webapp frontend. I will have the webservice on a server somewhere so that the React code can hit it to make API calls, but as far as serving the React webapp would it be better to do serve it with the same backend server or would it be better to make a seperate frontend server with something like express? Also, are there any other alternatives?
Share Improve this question asked Sep 15, 2016 at 14:36 dszopadszopa 3251 gold badge4 silver badges11 bronze badges1 Answer
Reset to default 8Serving the react webapp with either express or the same server as the REST backend is both valid options. I would say that if there is no specific reason for choosing express, serving it on the same server as the spring backend is your best choice.
Recall that the frontend and backend will still be decoupled and only municate through the REST-interface so to extend the backend-server to host the react-webapp should be quite simple, here's an example that could be helful: React,Spring,Rest example
However there is a couple arguments that I see that could make you choose a separate server then the REST backend, for example:
Isolated restarts and failures. If you want to be able to restart only your react-frontend without affecting the REST backend you will probably want to run them on different servers. Another thing to consider is if you expect that the backend will need to scale heavily and you'll need to replicate the backend across multiple servers, that might be easier to do if the frontend is running on its own separate server.
Server-side rendering of JavaScript (React) is possible through a node.js server like express but I don't think it is possible with a Spring server.
Also, are there any other alternatives?
Other alternatives then express/Spring, Yes. Other alternatives then hosting the fronted on the backend-server or on its own server? No
There are pros and cons with both choices and what is best depends on your needs.
本文标签: javascriptHow to serve a decoupled React frontendStack Overflow
版权声明:本文标题:javascript - How to serve a decoupled React frontend? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744228449a2596207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论