如何在服务中自动更改 URL,更改 URL 后,它应该影响所有组件,而无需在 angular6 中保存/构建/运行 [英] How to change URLs automatically in services, after changing URL it should affect to all components without saving/ building/running in angular6

查看:12
本文介绍了如何在服务中自动更改 URL,更改 URL 后,它应该影响所有组件,而无需在 angular6 中保存/构建/运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在托管一个带有 angular 6 的新应用程序,并且我们有许多带有 diff URL 的服务器,我想自动更改它们(如 Java 中的 .property 文件).在谷歌搜索后,我得到了一些答案,比如更改 environment.ts 文件中的路径,因此它会影响所有组件.但它不完全是我的要求,这意味着如果我更改 environment.ts 文件中的 URL,我们应该保存该文件,我们需要再次编译它.所以这正是我面临的问题,我不想保存/编译文件.

We are hosting a new application with angular 6 and we have many servers with diff URLs, i want to change them automatically(like .property file in java). after searching in google i got some answers like changing paths in environment.ts file, so it will affect to all components. but its not exactly my requirements, means if i change URL in environment.ts file, we should save the file and we need to compile it once again. So exactly this is the problem i am facing, i don't want to save / compile the file.

请在这种情况下帮助我.

Please help me in this situation.

service.ts 文件.

service.ts file.

emplLoginCheckUrl = this.baseUrl+"/checkValidUser";

我试图从 environment.ts 文件中更改基本 url,它工作正常,但在保存文件后,我不希望保存文件应该自动更改.

i tried to change base url from environment.ts file, its working correctly but after saving the file, i dont want want save file it should change automatically.

.service.ts 文件.

.service.ts file.

 emplLoginCheckUrl = this.baseUrl+"/checkValidUser";

       validateUserDetails(employeeDetails): Observable<any> {
            console.log(this.baseUrl);
            return this._httpClinet.post(this.emplLoginCheckUrl, employeeDetails);
        }

environment.ts 文件.

environment.ts file.

export const environment = {
  production: false,
  baseUrl: "http://rest/somerestservice"
};

预期:

URL 应该自动更改,而无需一次又一次地保存/运行/编译/构建,因为只有一次我可以在托管时进行保存/运行/编译/构建.托管后如果我想更改网址我不能去那里,更改路径并且无法再次编译它.

URLs should change automatically without saving/running/compiling/building again and again, because only one time I can do saving/running/compiling/building while hosting. after hosting if I want to change URLs I can't go there, change the path and cant compile it once again.

推荐答案

这基本上就是众所周知的文件"了图案.它是 Web 服务器上公开配置信息的路径.应用程序在引导时必须通过 HTTP 请求获取实时配置,并且可以通过重新获取数据来刷新配置.

This is basically the "well known file" pattern. It's a path on a web server that exposes config information. The applications have to fetch the live config via a HTTP request while they are bootstrapping, and can refresh the config by re-fetching the data.

https://ma.ttias.be/众所周知的目录-网络服务器-aka-rfc-5785/

它基于 IETF RFC:

It's based on an IETF RFC:

https://www.rfc-editor.org/rfc/rfc5785

这篇关于如何在服务中自动更改 URL,更改 URL 后,它应该影响所有组件,而无需在 angular6 中保存/构建/运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆