Reputation: 41
I have more than 1 server running on different ports.
http://localhost:8081
http://localhost:8082
http://localhost:8083
Currently, I can connect all modules/library of my Angular 2 application to any single server.
However, how to connect different library with different servers?
I am following micro-service approach for Angular application following this article,
Upvotes: 1
Views: 519
Reputation: 41
Currently, we are using the micro-frontend approach to connect with different services. https://micro-frontends.org/
Upvotes: 2
Reputation: 1547
I would suggest you to take use of environment variables that you inject into your services (assuming you have one for each service lib) each one with a specific variable and once done you can run the cli with(depending what version of the cli you running):
ng build --env
or
ng build --prod --env=prod
with minified production code.
and in your env files:
environment.ts:
export const environment = {
production: false,
libOneUrl: 'http://localhost:8081',
libTwoUrl: 'http://localhost:8082',
libThreeUrl: 'http://localhost:8083',
};
and in your service.ts inject it by:
import { environment } from '../../environments/environment';
apiUrl = environment.libOneUrl;
for dev resp. prod build do same in the files environment.dev.ts resp. environment.prod.ts (set production variable to true for prod build).
Upvotes: 2