Open pimlie opened 5 years ago
Thanks for discovery @pimlie. What do you think if we default browserBaseURL
to be relative part of baseURL
so if baseURL=http://localhost/api
then browserBaseURL
will be /api
.
That would probably be even better :)
@pi0 btw, will submit a pr for this in a couple of minutes (unless you are quicker)
Oops! And we probably need to check for the same origin (which is impossible for default value as it is in the module, not runtime!) If baseURL is external like https://api.example.com or even http://localhost:8080/api it should be preserved as is not /
or /api
for browserBaseURL.
It seems explicitly passing browserBaseURL is safer. We can only do this in proxy mode (proxy: true
) where API is pointing to the same origin.
Hmm, probably easier/faster if you have a look at this otherwise cause I am not as fast as you understanding what you mean? Eg isnt checking origin an extra feature?
Checking again the issues, what should we do about this?
As mentioned above, it is only safe when serving API on same domain using either proxy, serverMiddleware or serverless functions (and also taking into account that fetching another ssr route can cause infinite loop). There was also another nice idea (i guess in axios) using window.location
to get browser baseURL.
I think the best would be in a major release for both axios and http, we don't have any defaults (no baseURL options) and and a new option that indicates a relative path on same domain to be marked as api endpoint. (basePath: '/api'
and baseDomain: 'https://google.com'
)
What problem does this feature solve?
Currently the default value of
browserBaseUrl
isbaseUrl
which works correctly if you are running your server on localhost as well. But when running Nuxt withHOST=0.0.0.0
then baseUrl and thus browseBaseUrl still fallbacks to localhost. This is fine for baseUrl, but browserBaseUrl shouldnt probably be pointing to localhost.Related issue: https://github.com/nuxt/press/issues/2 (as fix in nuxtpress I just added
browserBaseUrl: '/'
as option)What does the proposed changes look like?
Set default value for browserBaseUrl to
/