nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

Allow change of baseURL in onRequest hook #82

Closed ThePeach closed 4 years ago

ThePeach commented 5 years ago

What problem does this feature solve?

this is very much a runtime/environment variable issue. In order to use variables defined by nuxt-env, I would have to have access to the app object. This is something currently doable with the axios module

What does the proposed changes look like?

the config object should have have a baseURL variable, and the final url shouldn't be computed already.

atinux commented 4 years ago

HI @ThePeach

Do you mind showing us some code of what you are trying to achieve please? :)

ThePeach commented 4 years ago

hi @Atinux. sorry for this late reply but my inbox is swamped and it's hard to keep track of replies for some reason I'm not getting notified. Anyhow the problem I've faced is that the baseUrl variable will need to be defined at build time, and can't be updated dynamically at runtime. The main objective for me is in a universal app, in conjunction with nuxt-env module, in order to have a "build one, run everywhere" type of app.

I hope this makes sense.

atinux commented 4 years ago

Actually if you use nuxt start, you can use the proxy of axios and set the proxied url on tu time directly :)

atinux commented 4 years ago

With v0.5.0, you can now use $http.setBaseURL.

This way, you can create a plugin to set the baseURL based on something like ˋ$store.state.baseURL` combined with nuxtServerInit where you can get access to server env.