ng-build上的端口和代理配置 [英] Port and Proxy Config on ng-build
问题描述
例如,我有一个运行在int.myapp.com上的前端,它是运行在int.backend.myapp.com上的后端.我以为可以用proxy.config.json进行复制:
I have a frontend running for example on int.myapp.com and it's backend on int.backend.myapp.com. I thought I can do the proxing with the proxy.config.json like this:
"/api": {
"target": "https://int.backend.myapp.com",
"secure": true,
"changeOrigin": true
}
在我的package.json文件中
And in my package.json file
"start": "ng serve --proxy-config proxy.conf.json"
一切都可以在我的开发环境中进行.
Everything works on my dev environment.
但是当我开始生产时:
ng buil --prod
并在Firebase上部署
and deploy on firebase
firebase deploy
Web应用程序无法与API通信
The web application is not able to communicate with the API
我该如何解决?
推荐答案
万一其他人遇到此问题,我发现了一种解决方法,以防您仍然想在本地运行 角度应用程序,请使用http-server应用程序:
In case anybody else run into this problem, I found a workaround in case you still want to run locally your production angular application, use the http-server application:
npm install -g http-server
构建生产应用程序:
ng build --prod
转到您的dist/[YOUR_APP_NAME_FOLDER]文件夹:
Go to your dist/[YOUR_APP_NAME_FOLDER] folder:
cd dist/[YOUR_APP_NAME_FOLDER]
运行http-server应用程序,并将Proxy选项(--proxy或-P)与您要指向的后端代理一起传递:
Run the http-server application and pass the Proxy option (--proxy or -P) with the backend proxy you would like to point to:
http-server -c-1 -P http://localhost:3000 .
这篇关于ng-build上的端口和代理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!