简体   繁体   English

Node.js Provider Rest API和angular.js Web应用程序

[英]Node.js Provider Rest API and angular.js WEB APP

I'm developing an Rest API in Node.js / express to expose resources (to Backend). 我正在Node.js / express中开发Rest API ,以向后端公开资源。 And another web application that manages Sessions and interacts with the Rest API (to Frontend). 还有另一个Web应用程序 ,用于管理会话并与Rest API (到前端)进行交互。 API and WEB_APP, is in same domain, with subdomain in both: API和WEB_APP位于同一个域中,两者都具有子域:

  • Backend: api.example.com 后端:api.example.com
  • 2 Frontend: www.example.com 2前端:www.example.com

The web application is accessed from client with angular.js . Web应用程序是使用angular.js从客户端访问的。

The architecture would be for two situations: 该体系结构适用于两种情况:

Main_Rest_API <-> WEB_APP <-> Browser_User Main_Rest_API <-> WEB_APP <-> Browser_User
Main_Rest_API <-> Rest_SDK <-> Client Main_Rest_API <-> Rest_SDK <->客户端

My question is: This architecture is consistent? 我的问题是:这种架构是一致的吗? What would be the best way to implement this scheme? 实施该计划的最佳方法是什么?

Update: 更新:

I have to implement this architecture to provide Restfull via OAuth2 to third-party clients also 我必须实现此架构,才能通过OAuth2向第三方客户端提供Restfull

I don't really understand your question, 我不太了解你的问题

are you sure that you need separate servers for serving the web app and for the API? 您确定需要单独的服务器来提供Web应用程序和API吗? you'll need to handle cross domain requests this way. 您将需要以这种方式处理跨域请求。

if you don't actually need two servers, it'll be simpler to have one app, where /api/ routes (for example) are the REST API. 如果您实际上不需要两台服务器,那么拥有一个应用程序会更简单,其中/ api /路由(例如)是REST API。 then your AngularJS app can make AJAX requests to /api/ and / will serve the JavaScript web app. 那么您的AngularJS应用可以向/ api /发出AJAX请求,并且/将投放JavaScript Web应用。

again, I don't understand your question for the case you do need two separate servers. 同样,对于您确实需要两个单独的服务器的情况,我不明白您的问题。

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

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