Reputation: 694
I've deployed my Angular 6 based application to apache server. Everything works fine however proxy not working. Proxy configurations works well on localhost. When I built an application and deployed to the apache server. All api calls thrown 404 error.
Here is my proxy.conf.json file:
{
"/api": {
"target": "https://api.mywebpage.com",
"secure": false,
"pathRewrite": {
"^/api": "/v1"
},
"changeOrigin": true,
"logLevel": "debug"
}
}
Are there something need to append .htaccess file to use these proxy settings? Am I missing something?
Upvotes: 0
Views: 293
Reputation: 2249
The proxy config is passed on the the ng serve
method.
This is used to configure the local development environment. It will boot up a local proxy rest service outside of your application that will reroute your requests to the api in order to avoid any CORS issues during development.
The build output is just plain old javascript and html.
So your solution:
1) quick and dirty: create an http interceptor that changes the url at runtime
or
2) create a config object in which you configure the base url. Inject the config in your services and use that object to create your api url. You can use the environment to put you local urls in there and environment.prod to store your live urls.
Upvotes: 1