简体   繁体   English

如何以角度设置相对基本 URL

[英]How to set relative base URL in angular

Hi I checked answers around but none worked for me as expected, basically the problem is that I want to set my URLs protocol and domain name dynamically in angular service.嗨,我检查了周围的答案,但没有一个对我有用,基本上问题是我想在 angular 服务中动态设置我的 URL 协议和域名。 Here's my code for example:这是我的代码,例如:

baseUrl: string = 'http://localhost:8080/test/rest/employees/'

if i use this form as seen in other posts it doesn't work:如果我使用在其他帖子中看到的这种形式,它就不起作用:

baseUrl: string = '/test/rest/emplyoees/'

You might need to add a proxy.conf.json file.您可能需要添加一个proxy.conf.json文件。

{
    "/": {
        "target": "http://localhost:8080",
        "secure": false,
        "changeOrigin": true
    }
}

Angular checks for this file and automatically appends it to the api requests. Angular 检查此文件并自动将其附加到 api 请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM