I am currently using now.sh
for deploying my app. Recently, I decided to move the baseUrl
for requests to a proxy.config.json
file.
{
"/api/*": {
"target": "http://localhost:3000",
"secure": false,
"logLevel": "debug"
}
}
For deploying with now.sh
I change the scripts
in package.json
to:
"start": "serve dist/ --single",
"build": "ng build --prod",
so, first, I did a ng build
.
The thing is, I'm needing a different target
for proxy.config.json
, because I deployed an API and I want to use it in the production app
I was thinking on having two files proxy.config.dev.json
and proxy.config.prod.json
, but I don't know if I can target a different proxy with the cli
. The problem is that I'm using serve
for production and not ng serve
so proxy-config
is not available.
What do you suggest? How can I get to work it?
A reverse proxy is a server that retrieves resources for clients from one or more upstream servers. It typically places itself behind a firewall in a private network and forwards clients request to these upstream servers.
conf. json" }, You can use the proxying support in the webpack dev 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.
I have realized that is a better solution to use "environments" which came by default with angular-cli
.
So I setup a baseUrl
in both environments {dev, prod}
. And then the builds will not change. Then you have to modify your services to use this env variable.
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