API单页的应用程序

API单页的应用程序

本文介绍了有哪些技术部署依赖于一个REST API单页的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了从REST API的数据呈现在一个页面应用程序(使用AngularJS)调用它使一个遗留系统。这个遗留系统是非常大的,用Java编写的,并需要几分钟来部署,所以我们决定这将是更具生产力发展的单页应用完全从遗留系统是分开的。

I'm building a Single Page Application (using AngularJS) that renders data from a REST API call it makes to a legacy system. This legacy system is very large, written in Java and takes minutes to deploy so we decided it would be more productive to develop the Single Page Application completely separate from the legacy system.

出现的问题,一旦我们试图与遗留系统的REST API进行通信。虽然这两个应用程序是在本地部署到同一台主机,他们被部署在不同的应用服务器,所以我需要通信时使用不同的端口。但由于SPA在传送给REST API的不同端口上,浏览器prevented我的要求,以防止的

The problems occurred once we tried to communicate with the legacy system's REST API. Although both apps were deployed locally to the same host, they were deployed on different app servers so I needed to use different ports when communicating. But because the SPA was communicating to a REST API on a different port, the browsers prevented my requests to protect against Cross Site Scripting attacks.

我们发现这个构建工具名称(即利用咕噜声),使得它很容易将HTTP请求代理。这让我们周围的跨站脚本限制,但这只是适用于开发模式。

We found this build tool name lineman (that leverages grunt) that made it easy to proxy http requests. This got us around the cross site scripting limitation but this was only suitable in development mode.

现在,我们已经有了概念,工作的证明,我们想知道我们应该如何这些应用程序没有代理一起部署。这是我很难找到如何做到这一点建议,因为角度不承担您必须摆在首位后端并在前端使用角度大多数人都没有在后端使用Java(如果连事项)

Now that we've got a proof of concept working, we want to know how we're supposed to deploy these apps together without the proxying. It's hard for me to find advice on how to do this because Angular doesn't assume you have a backend in the first place and most people that use Angular on the front end aren't using Java in the backend (if that even matters).

我们正在运行到像时,应用程序上下文路径的问题也会有所不同,所以我们一直的巧妙的方法来避免两种模式工作,断开链接总得想,如果他们部署在PROD模式VS开发模式。我不知道/我在哪里拐错了一步这里沿途。我应该避免从后端的独立服务器上开发SPA?

We're running into issues like, the context paths of the apps change depending on if they're deployed in prod mode vs dev mode so we've gotta think of clever ways to avoid broken links that work for both modes. I wonder if/where I took a wrong step here along the way. Should I avoid developing the SPA on a separate server from the backend?

推荐答案

我把apache的前面,并使用mod_proxy的作为反向代理的应用程序。

I would put apache in front and use mod_proxy as a reverse proxy to the apps.

说你的REST API是在http://本地主机:9000。如果角度应用仅仅是静态的资产,你可以直接在Apache部署。如果没有你反向代理它。
对于REST API yoivsetup的发言权/ API反向代理为localhost:9000。所以,打在 apache的任何请求都将现在被转发到遗留系统。现在固定角度的应用程序和你做。
对于地方的发展,您可以使用节点-HTTP代理是缓解设置类似的方式。

Say your REST API is at http ://localhost:9000. If the angular app is only static assets you can deploy it directly under apache. If not you reverse proxy it as well.For the REST api yoivsetup a reverse proxy for say /api to localhost:9000. So any request hitting the apache at http://some.host.name/api will now be forwarded to the legacy system. Now fix the angular app and you are done.For local development you can use node-http-proxy which is ease to setup in a similar fashion

这篇关于有哪些技术部署依赖于一个REST API单页的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 18:58