简体   繁体   中英

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. 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.

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

Angular checks for this file and automatically appends it to the api requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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