如何使用nodejs实现前后端分离?
目前我开发的系统中,nodejs负责后端逻辑API、业务路由、渲染web前端和前端的路由关系。
结果一切都围绕着nodejs转,完全谈不上分离。
优秀的nodejs的前后端分离方案应该是怎么样的?
PS1:
现在不是很多人都在推崇使用nodejs等后端对前端进行渲染来提高加载效率吗?
如果单是做前后端分离所有请求就都用AJAX就搞定了,但是效率问题又来了。
如果把前端页面都做成模板(我用的是ejs),前后端的耦合度又太高了。
不知应如何处理这个问题,有没有成型的方案,毕竟我资历比较浅,处理不好这种问题。
PS2:
因为nodejs+前后端分离+全栈这几个概念比较火
就想着能不能利用nodejs知识 尝试一下新的东西
最好以后能同时比较好的管理webapp之类的跨平台项目的框架
(算是一劳永逸?!)
http://ued.taobao.org/blog/category/bowen/frontend/
Taobao UED’s solution actually treats Node as part of the big front-end.
Just use angular. The front-end business logic is completed in the angular controller. Use $http to request data from the node.
Nodejs only renders the page, and the data is provided by java
Any good answers?
I am also thinking about this issue. In the practice of front-end and back-end separation, nodejs can be used alone as a page template rendering, but how to use it specifically, how to combine it with the front-end MVVM framework, and how to share routing?
Taobao mentioned xTemplate, does it mean that xTemplate is used directly to render the page template after the Node layer obtains the data? Then the front-end MVVM framework does not need routing or what?
If the backend also uses Nodejs, it feels a bit weird to write the api alone
I am using vuejs now.
I am very confused. I wonder if the question has been answered after a few months? Thank you thank you
Answer:
The current focus of separation is to let the front-end use node to render the template page. If the subject wants to use full-stack nodejs and wants to separate, the back-end API should still be implemented with Nodejs, and the front-end should still use Nodejs for rendering. , this achieves separation. As long as you are not doing things alone, there will be no hindrance even if the team uses the same language to do the front-end and back-end. At least the division of labor is clear and clear,
Separation of front-end and back-end does not matter what technology we use to implement the back-end API. It is ok. The point is that the front-end needs to take on more work than before, that is, obtaining data and rendering page templates, so that the front-end and back-end Get rid of the previous interweaving of ambiguous code and achieve separation of work.