本文介绍了Angular-每个客户的远程API的基本URL映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个 Angular 7.2.* Web应用程序,用于单个远程API URL.为了更加清楚,举一个例子:

Currently I have an Angular 7.2.* web application which is used against a single remote API URL. To be more clear, an example:

export const environment = {
    ...
    production: true,
    baseUrl: 'https://remote-api-url/'
}

然后将此 environment.baseUrl 值用于 *.service.ts 类中的数据I/O操作.

This environment.baseUrl value is then used inside *.service.ts classes for data I/O operations.

现在,说我需要将此应用程序出售给多个客户,如何自定义 environment.baseUrl 每个客户?是否可以在没有的情况下为每个客户提供单独的构建/单独的 environment 文件?

Now, say I need to sell this application to multiple customers, how do I customize the environment.baseUrl per customer? Can this be done without having a separate build / separate environment file per customer?

我想阅读您对此的想法.构建结果将打包"为Docker映像.

I'd like to read your ideas on this.The build result will be "packaged" as a Docker image.

推荐答案

我所做的是制作一个带有url的配置文件:

What I did was make a config file with an url:

{ "url": "yourURL" }

将此添加到资产地图,然后执行:

Add this to the assets map and then do:

this.http.get('./assets/config.json')
                .pipe(map(res => res))
                .toPromise() // or subscribe
                .then((config: any) => {
                    this.config = JSON.parse(config._body).url;
                });

这篇关于Angular-每个客户的远程API的基本URL映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:38