Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change browserBaseUrl default value to '/' #54

Open
pimlie opened this issue Jun 21, 2019 · 7 comments
Open

change browserBaseUrl default value to '/' #54

pimlie opened this issue Jun 21, 2019 · 7 comments
Labels

Comments

@pimlie
Copy link
Contributor

pimlie commented Jun 21, 2019

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: nuxt/press#2 (as fix in nuxtpress I just added browserBaseUrl: '/' as option)

What does the proposed changes look like?

Set default value for browserBaseUrl to /

@pi0
Copy link
Member

pi0 commented Jun 21, 2019

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.

@pimlie
Copy link
Contributor Author

pimlie commented Jun 21, 2019

That would probably be even better :)

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

@pi0
Copy link
Member

pi0 commented Jun 21, 2019

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.

@pi0
Copy link
Member

pi0 commented Jun 21, 2019

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.

@pimlie
Copy link
Contributor Author

pimlie commented Jun 21, 2019

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?

@atinux
Copy link
Member

atinux commented Oct 16, 2020

Checking again the issues, what should we do about this?

@pi0
Copy link
Member

pi0 commented Oct 16, 2020

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants