question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative URLs don't work as baseURL in 0.20 (browser)

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tenkillercommented, Sep 29, 2020

@Djunnni

as you know, defaults baseURL need protocol and address where to request

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.

1reaction
chinesedfancommented, Sep 12, 2020

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.

<!-- the CDN points to 0.20.0 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
    axios.defaults.baseURL = '/images';
    axios.get("/cat.jpg");
</script>
Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found