AngularJS:服务器端架构 [英] AngularJS: Server Side Architecture

查看:113
本文介绍了AngularJS:服务器端架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在公司内部网中,我们有一些端点服务平台,例如BPM,文档管理系统等.这些端点服务公开了REST API.我们使用AngularJS作为前端开发Web应用程序.

关于如何从AngualJS调用这些终端服务有两种选择.

选项1:鉴于这些终端服务公开了REST,请直接从AngualrJS调用这些REST API.

选项2:引入中间层(在WebLogic或Tomcat等应用服务器上).构建一个调用端点REST API的Java应用程序层;并将其托管在此millde层上. AngularJS调用此中间层提供的REST;该中间层依次调用端点REST.

我个人更喜欢选项1;但是,我邀请您就此事发言.我列出了方案1的优缺点.

选项1的优点:

  • 更好的性能(吞吐量)使HTTP请求的跳数减少了.
  • 由于少了一个组成部分,因此较少的开发/部署工作.
  • 更少的故障点数.如果有问题,我们可以在AngualrJs或最终服务中了解它.

选项1的缺点

  • 安全问题?不确定-希望对此发表专家意见.
  • CORS:最终服务将需要启用对适当域的Access-Control-Allow-Origin.
  • 记录不佳?如果出现问题,日志将仅在用户计算机(IE/Chrome开发工具)或最终服务上可用.
  • AngualJS层中的处理太多了吗?此处理主要是分析最终服务的结果.这还取决于所使用的最终服务的类型.
我认为

解决方案

从长远来看,选项2是更好的选择.这样做的原因很少.

安全是第一位的,如果在两者之间使用中间件,则可以具有固有的安全性,这意味着您只能公开您的web应用需要的REST API.由于您可以控制中间件,因此还可以包括oAuth之类的安全机制.

记录是另一种记录.确保当今的任何应用程序确实都需要某种审核.安全性和日志记录都是您实际的REST调用之前的层.

您将能够在任何关键的REST API上添加一些方面,以便在调用该API的情况下触发邮件,即使我们目前不需要这些灵活性,也总是很方便的.

您可以有效地包括响应转换和错误处理.一旦从服务中获得响应,就可以在中间件中转换响应,删除不必要的字段或关键字段,设置一些值等.所有这些都可以通过angular完成,但是真正的响应或错误就会暴露给客户端./p>

在不利的一面,您正确地提到性能是一种性能,但imo使REST中间件与服务REST保持同步更加糟糕.服务添加的任何新API都需要包含在中间件中,并进行重新编译和重新部署.但这还取决于这些变化的可能性和频率是多少?对于任何这些更改,您无论如何都可能需要更改angular webapp才能将其包括在内.

Within our corporate intranet, we have a few end-point service platforms like BPM, document management system, etc. These end-point services expose REST API. We develop web applications using AngularJS as front end.

There are two options on how we can make calls from AngualJS to these end-point services.

Option 1: Given these end-point services expose REST, call these REST API directly from AngualrJS.

Option 2: Introduce a middle layer (on an application server like WebLogic or Tomcat). Build a Java application layer that calls into the end-point REST API; and host it on this millde layer. The AngularJS calls into REST provided by this middle layer; this middle layer inturn calls into the end-point REST.

I personally prefer the Option 1; however I invite your openion on this matter. I have listed the pros and cons of Option 1 as I see them.

Pros of Option 1:

  • Better performance (throughput) given one less hop for HTTP requests.
  • Lesser development/deployment efforts due to one less component.
  • Lesser number of points of failure. If there is an issue, we know its either in AngualrJs or the end service.

Cons of Option 1:

  • Security issues? Not sure of this - would like expert comments on this.
  • CORS: the end services will need to enable Access-Control-Allow-Origin to appropriate domains.
  • Poor logging? If something goes wrong, the logs will be available only on user machines (IE/Chrome development tool) or on the end service.
  • Too much processing in AngualJS layer? This processing is mainly parsing the result from end service. This also depends on the kind of end service that is being used.

解决方案

option 2 in my opinion is a better option in long run. There are few reasons for that.

Security is first and foremost, If you have a middleware in between, you can have inherent security, which means you can expose only those REST APIs which your angular webapp needs. You can also include a security mechanism like oAuth since you control the middleware.

Logging is another one. for sure any application nowadays do need some sort of auditing. both security and logging are layers before your actual REST calls.

You would be able to add some aspects on any key REST API, such that in case if that API is called trigger a mail, it's always handy to have those flexibility even we don't need at the moment.

You can include response transformation and error handling efficiently. Once you get the response from service, in your middleware you can transform the response, remove unnecessary or critical fields, conjure some values etc. This all can be done with angular also but then the real response or error is exposed to the client.

On the downside you rightly mentioned performance is one but imo keeping your REST middlware in sync with services REST is more bane. any new API added by services, needs to be included in middleware, recompiled and redeployed. But it also depends what are the likelihood and frequency of those changes? for any those changes you anyhow might need to change in angular webapp to include it.

这篇关于AngularJS:服务器端架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆