nuxt / http

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

Allow access to baseURL? #164

Closed sundowndev closed 3 years ago

sundowndev commented 3 years ago

Hi, I need to access baseURL property in a template, is it possible to add a getter for it?

Thanks

atinux commented 3 years ago

By simply looking at https://github.com/nuxt/http/blob/master/lib/plugin.js#L17

You should be able to use this.$http._defaults.prefixUrl. What would be the usage of accessing the baseURL?

sundowndev commented 3 years ago

By simply looking at https://github.com/nuxt/http/blob/master/lib/plugin.js#L17

You should be able to use this.$http._defaults.prefixUrl. What would be the usage of accessing the baseURL?

Let's say I have a property url from my REST API, I'd like this url be a link in my template. Problem is this URL is not always absolute (e.g: /uploads/123.pdf). So I need a way to use the prefixUrl when needed.

this.$http._defaults.prefixUrl does not seem to have a TS signature, this is intended to be a private property, isn't it?

atinux commented 3 years ago

We never had the case to expose it honestly. I guess we can add a getter for it, what do you think @pi0 ?

pi0 commented 3 years ago

PR welcome to expose $http.baseURL but generally it would be much better if exposing baseURL via runtime config ($config.baseURL) to generate such links instead of depending on http client instance

sundowndev commented 3 years ago

Fixed by #165