如何在服务中自动更改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
问题描述
我们正在托管一个角度为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应该自动更改,而无需一次又一次地保存/运行/编译/构建,因为只有一次我可以在托管时进行保存/运行/编译/构建.托管后,如果我想更改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/well-known-directory-webservers-aka-rfc-5785/
它基于IETF RFC:
It's based on an IETF RFC:
https://tools.ietf.org/html/rfc5785
这篇关于如何在服务中自动更改URL,更改URL后将影响所有组件,而无需在angular6中保存/构建/运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!