简体   繁体   English

如何web用户界面+ node.js和快速路由

[英]How to web user interface + node.js and express routing

I have server with node.js + express for routing. 我有node.js + express的服务器用于路由。 When I do requests like http://mydomain.com/photos , http://mydomain.com/photos/123 , etc I got JSON answer. 当我不喜欢请求http://mydomain.com/photoshttp://mydomain.com/photos/123 ,等我得到JSON的答案。 This is OK and exactly what I need. 这没关系,正是我需要的。 So RESTful API is ready. 所以RESTful API准备好了。 But this is just data and I need also to process this data and show it as webUI (html, css, angularjs). 但这只是数据,我还需要处理这些数据并将其显示为webUI(html,css,angularjs)。

How to implement webUI for this purpose properly? 如何正确实现webUI?

I need to have unique independent server API in order to use it for different clients: browser web site, mobile apps, etc. 我需要拥有独特的独立服务器API才能将其用于不同的客户端:浏览器网站,移动应用程序等。

You probably want something like the MEAN stack: MongoDB + Express + AngularJS + NodeJS. 你可能想要像MEAN堆栈这样的东西:MongoDB + Express + AngularJS + NodeJS。

Your client (AngularJS) is being delivered somehow (static hosting, express, cdn, nginx, etc) and then performs REST requests to an external server (Rails, Express, Php, etc) that has CORS enabled if lives in a different domain. 您的客户端(AngularJS)以某种方式交付(静态托管,express,cdn,nginx等),然后对外部服务器(Rails,Express,Php等)执行REST请求,如果它们位于不同的域中,则启用CORS。 This structure is known as Single Page Applications (SPA) , where a single big HTTP request is loaded in order to interact with a backend. 此结构称为单页应用程序(SPA) ,其中加载单个大HTTP请求以便与后端进行交互。

That being said, this is nothing new... things like CouchDB, SammyJS and so on had been working on this for a couple years now. 话虽如此,这并不是什么新鲜事......像CouchDB,SammyJS等一直在研究这个问题几年了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM