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.

Making requests relative to current domain

See original GitHub issue

### Summary

Hello,

I’m developing a web app and I’m using axios. I was a very happy user until I had to deploy to my production server. On the production server, my app is served under a subdomain, so making the entire application work both on a root domain (for development) and on a subdomain was a bit painful. However, for my surprise, making axios requests work on both sides was very easy. So easy that I’m not sure if it is intentional or a bug. Before my requests was like

axios.get('/api/licenses')

So serving the app from https://example.com/licenses resulted on a request to https://example.com/api/licenses instead of the expected https://example.com/licenses/api/licenses.

After that, I just tried to remove the prefixing slash, so my request looked like:

axios.get('api/licenses')

That produced the desired result of making the request to https://example.com/licenses/api/licenses. I am very happy with this, because now I can develop my app without hassle. However, this behavior is not documented on any place, all the examples makes requests to the root of the domain, and I’m scared of this cool feature disappearing on future releases.

### Context

  • axios version: e.g.: v0.16.1
  • Environment: chrome 57

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
rubennortecommented, Aug 13, 2017

This is just how relative URLs work in the browser. Axios doesn’t have anything special about it.

5reactions
danielo515commented, Aug 22, 2018

What about axios.get('./path') ? Why isn’t that respecting the relative of the path ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I request a resource (relative path) from the current ...
Well, you can always use something like: private string CurrentDomain() { string currDomain = Request.Url.Scheme + System.Uri.
Read more >
Absolute vs Relative URLs: when to use which for SEO?
A relative URL is a URL that only includes the path. The path is everything that comes after the domain, including the directory...
Read more >
HTML and URLs
Relative URLs may contain relative path components (".." means one level up in the hierarchy defined by the path), and may contain fragment...
Read more >
Paths explained: Absolute, relative, UNC, and URL—Help
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a...
Read more >
What Is the Difference Between a Relative and an Absolute ...
The relative path starts with the forward slash and leads the browser to stay within the current site. An example of a relative...
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