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
}
And in my package.json file
"start": "ng serve --proxy-config proxy.conf.json"
Everything works on my dev environment.
But when I build for production :
ng build --prod
and deploy on firebase
firebase deploy
The web application is not able to communicate with the API
How can I do to fix it ?
Use the proxying support in the webpack development server to divert certain URLs to a backend server, by passing a file to the --proxy-config build option. For example, to divert all calls for http://localhost:4200/api to a server running on http://localhost:3000/api , take the following steps.
ng buildlink. Compiles an Angular application or library into an output directory named dist/ at the given output path.
The ng build command is intentionally for building the apps and deploying the build artifacts. The command does not generate an output folder. The output folder is – dist/. The ng serve builds artifacts from memory instead for a faster development experience.
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
Build your production application:
ng build --prod
Go to your dist/[YOUR_APP_NAME_FOLDER] folder:
cd dist/[YOUR_APP_NAME_FOLDER]
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With