christianmalek / vuex-rest-api

A utility to simplify the use of REST APIs with Vuex
http://vuex-rest-api.org
MIT License
382 stars 48 forks source link

empty baseUrl results in undesired default '/api' #60

Closed vesper8 closed 6 years ago

vesper8 commented 6 years ago

As a result of wanting to use @websanova/vue-auth, I set a global axios root like this:

axios.defaults.baseURL = '/api';

This results in my auth calls being made to /api/auth/login

This seems to be conflicting with my vapi resources however.

Previously I was setting the baseUrl to '/api' in each of my vapi resources

But this was resulting in calls being made to /api/api/posts

I tried setting baseUrl to '' as well as commenting it altogether and both of these seem to have no effect.. calls are still being made to /api/api/posts instead of /api/posts

Oddly enough however, if I change baseUrl to '/test' then it starts to make calls to /api/test/posts

So it seems like it's not possible to have a blank value as it just defaults to '/api'

Bit puzzled on how to proceed.. your thoughts would be appreciated! Thanks!

christianmalek commented 6 years ago

Hello @vesper8 !

The baseURL gets normalized, see https://github.com/christianmalek/vuex-rest-api/blob/v2/src/Resource.ts#L110.

There could be a bug. The problem could be that - if axios.defaults.baseURL is set AND baseURL in the Vapi constructor - that both baseURLs will be concatenated.

christianmalek commented 6 years ago

I've fixed it. See https://github.com/christianmalek/vuex-rest-api/blob/v2/CHANGELOG.md#270-10042018 for more info.

vesper8 commented 6 years ago

awesome thanks for the quick fix!!