change browserBaseUrl default value to '/'

pimlie
928
pimlie
commented a month ago

What problem does this feature solve?

Currently the default value of browserBaseUrl is baseUrl which works correctly if you are running your server on localhost as well. But when running Nuxt with HOST=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 /

idea
0
pi0
29.8k
pi0
commented a month 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.

0
pimlie
928
pimlie
commented a month ago

That would probably be even better :)

@pi0 btw, will submit a pr for this in a couple of minutes (unless you are quicker)

0
pi0
29.8k
pi0
commented a month ago

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.

0
pi0
29.8k
pi0
commented a month ago

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.

0
pimlie
928
pimlie
commented a month ago

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?

0
Informations
Feature Request โ€ข Open
#c6 - Created a month ago