Relative URLs don't work as baseURL in 0.20 (browser)
See original GitHub issueDescribe the bug
On 0.19, I used to set baseURL to a relative URL like this:
axios.defaults.baseURL = '/api'
This would append /api
to the current window.location.host
, like this:
axios.get("/contracts/1/invoices") // GET https://{window.location.host}/api/contracts/1/invoices
On 0.20, setting baseURL like this has no effect. This occurs in all major browsers.
To Reproduce
axios.defaults.baseURL = '/images';
axios.get("/cat.jpg");
Run this in a browser
Expected behavior
GET {protocol}://{window.location.host}/images/cat.jpg
Environment
- axios 0.20.0
- All major browsers
Additional context/Screenshots
N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Could not get relativeURLs to work with {{ .Site.BaseURL }}
I've tried to enable relativeURLs = true in my configuration but any attempt to use {{ .Site.BaseURL }} still replace the urls with...
Read more >Browser resolves relative urls as if they were absolute
To make relative URLs to work properly, ending slash is required. I used it in the link from app #2, but not in...
Read more >Url in reqwest - Rust - Docs.rs
Creates a relative URL if possible, with this URL as the base URL. ... URLs that do not are either path-only like unix:/run/foo.socket...
Read more >How to handle relative urls correctly with a nginx reverse proxy
The problem is basically that using a proxy_pass directive won't rewrite HTML code and therefor relative URL's to for instance a img ...
Read more >URL handling options | Docs - TinyMCE
This option specifies the base URL for all relative URLs in the document. The default value is the directory of the current document....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Djunnni
That is incorrect. A URL with no protocol or host is a relative URL. This is a pretty basic understanding of how the Web works. And, it is indeed supported in Axios.
Failed to reproduce. Did I miss something? And what request url did you see in fact?
If deployed in local, the following test.html sends a request to
http://127.0.0.1:8080/images/cat.jpg
.