Reputation: 1933
I store the API base address in my environment class, and it gets reflected into the bundles after build. What i need is a way to somehow liberate this value from the build process so in case i wanna deploy the app under different servers with different API addresses, I won't have to do another build only for the sake of a new URL. My app is quite hefty and the build is really time-consuming.
Here is what is have in my environment.prod.ts :
export const environment = {
production: true,
configName: 'prod',
baseUrl: 'https://mpisitweb1/api'
};
Upvotes: 1
Views: 2259
Reputation: 326
I would try creating an environment.json that sits under your assets folder and make it publicly available. When your application is starting I'd do a request (On the same URL your serving from) to download that file which would contain the API baseUrl.
You'd have to store the value in Angular somewhere different though as you can't override the environment variable, might be best off putting it in a service somewhere that can be injected into the http Interceptor that way you can just specify "{BASE_URL}" as your base point and have the interceptor change it out to what's needed so the rest of your app isn't aware.
Upvotes: 2