Incorrect URL is being built when using relative paths.
See original GitHub issueHi,
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Thanks @arthurfiorette. I am closing this issue as I was to verify the fix successfully
@Chandu
v0.9.3