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.

Incorrect URL is being built when using relative paths.

See original GitHub issue

Hi, In my application I have the backend serve a static page at a specific path /clients/index.html and client api root is /clients/api Once the /clients/index.html is loaded, I need to get client information using the end point /clients/api/info.

I am using express for the backend and react for the frontend leveraging axios along with the axios-cache-interceptor.

However when using the axios instance (decorated by setupCache) with the baseURL set to : ‘/clients/api’ and the reqeust url set to /info, I am noticing a 404 error in the console.

Page URL: http://localhost:3010/clients/index.html Clients Information Endpoint: http://localhost:3010/clients/api/info

Working code:

var clientsApi = axios.create({
    baseURL: '/clients/api'
  });

  clientsApi.get('/info').then(a => {
    console.log('Received response: ', a.data);
  }).catch(err => {
    console.log('Error using vanialla axios');
    console.error(err);
  });

**Failing code: **

var clientsApiWithCache = AxiosCacheInterceptor.setupCache(axios.create({
    baseURL: '/clients/api'
  }));

  
  clientsApiWithCache.get('/info').then(a => {
    console.log('Received response using setupCache: ', a.data);
  }).catch(err => {
    console.log('Error using setupCache:');
    console.error(err);
  });

I have debugged the code and see that the issue occurs because of this line: https://github.com/arthurfiorette/axios-cache-interceptor/blob/dc27cd5b53b2d8847e8821a4607c7e3f25927bbc/src/util/key-generator.ts#L49

Any specific reason for trimming the slashes from the baseURL and url?

The repo @ https://github.com/Chandu/axios-cache-interceptor-relative-base-path-issue can be used to reproduce the issue (I haven’t used react in this repo for simpler setup, but the error can be reproduced ).

Screenshot showing the code/error

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Chanducommented, Mar 7, 2022

Thanks @arthurfiorette. I am closing this issue as I was to verify the fix successfully

0reactions
arthurfiorettecommented, Mar 4, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong relative path to URL assets when bundle lives ... - GitHub
Another possible solution is to join the URL with the publicURL option. This could be achieved by modifying the Asset#addURLDependency() ...
Read more >
Relative URL is relative to wrong absolute URL on web
The problem is that you have somehow not added a trailing slash to the first URL. If this directory actually exists on your...
Read more >
SASS relative url wrongly configured - Stack Overflow
I use react-router-dom for routing and relative paths work correctly in jsx files. I only have issue with urls in SCSS stylesheets.
Read more >
arcpy - ArcMap tool dialog says relative paths are incorrect
In the images above, I'm running the script in the toolbox and using the Item.shp as an input. However, it seems as though...
Read more >
I cannot create relative path links - CSS - Codecademy Forums
I am trying to make a basic website on visual studio code editor as ... is displayed and the picture will not appear...
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