如何使用代理设置部署Angular应用 [英] How to Deploy Angular app with Proxy Settings

查看:72
本文介绍了如何使用代理设置部署Angular应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代理配置文件,该文件具有API(网络服务)链接,可用于对我们的数据库进行调用.使用 npm start 可以使该代理配置在本地正常运行.

I have a proxy config file which has API(web service) link to target to make calls to our database. This proxy config is working fine locally using npm start .

现在,我需要将此应用程序部署到IIS上的生产Windows服务器. 我使用了 ng build ng build --prod ,看起来这不是通过代理设置生成的. 我需要有关如何生成具有代理设置的构建的帮助,以便将其部署到产品服务器.

Now I Need to deploy this app to our production windows server on IIS. I used ng build and ng build --prod looks like this is not generating build with proxy setting. I need help that How I can generate a build with proxy setting so that I can deploy it to prod server.

Api部署在其他某个域上,而此角度应用程序将部署在其他某个域上.

Api is deployed on some other domain and this angular app will be deployed on some other domain.

谢谢

推荐答案

代理配置文件用于本地开发Web服务器.使用它的主要原因是,这样一来,您可以在本地计算机上开发Angular应用和api时避免跨域请求,而不必在api中允许跨域请求.

The proxy config file is for the local development web server. The main reason you use it is so you can avoid cross domain requests when developing the Angular app and the api on your local machine without having to allow cross domain requests in the api.

当您发布产品时,不支持代理配置文件.您将发布到生产Web服务器.

When you release to production there is no support for the proxy config file. You will be releasing to your production web server.

如果您的api托管在同一域中,则不需要代理请求,因为它们不是跨域的;如果api在另一个域中,则需要允许api中的跨域请求.

If your api is hosted under the same domain then there is no need for proxying requests as they are not cross domain and if the api is on another domain you will need to allow cross domain request in the api.

这篇关于如何使用代理设置部署Angular应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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