- Set baseURL in interceptors is not working. #949
- Comments
- Baoyx007 commented Jun 9, 2017
- mrerhuo commented Jun 20, 2017
- hectim commented Jun 23, 2017
- baseURL settings do not take effect for axios #171
- Comments
- begueradj commented Oct 25, 2018 — with CMTY •
- Version
- Reproduction link
- Steps to reproduce
- What is expected ?
- What is actually happening?
- aldarund commented Oct 25, 2018 — with CMTY
- cmty bot commented Oct 25, 2018
- begueradj commented Nov 4, 2018
- aldarund commented Nov 4, 2018
- sangdth commented Feb 27, 2019
- marko-mlinarevic commented Mar 9, 2019
- mandaputtra commented Mar 31, 2019
- begueradj commented Mar 31, 2019 •
- sangdth commented Mar 31, 2019
- miyarappo commented Apr 6, 2019 •
- begueradj commented Apr 8, 2019
- This comment was marked as off-topic.
- dlodeprojuicer commented Apr 24, 2019 •
- DerekCrosson commented May 27, 2019
- skewness commented Oct 15, 2019
- genu commented Dec 18, 2019
- begueradj commented Dec 19, 2019
- pawel-marciniak commented Apr 23, 2020
- mandaputtra commented Apr 24, 2020
- trainoasis commented Dec 3, 2020
- johnson329 commented Jan 29, 2021
- pi0 commented Feb 1, 2021
- Setting baseURL in default configuration #175
- Comments
- nathanharper commented Dec 15, 2015
- mzabriskie commented Dec 17, 2015
- nickuraltsev commented Dec 17, 2015
- nathanharper commented Dec 17, 2015
- mzabriskie commented Dec 17, 2015
- nickuraltsev commented Dec 17, 2015
- nickuraltsev commented Dec 17, 2015
- mzabriskie commented Dec 21, 2015
- nickuraltsev commented Dec 21, 2015
- base url is not working #134
- Comments
- gomezmark commented Apr 23, 2018 •
- SnooHD commented Apr 23, 2018 — with CMTY •
- gomezmark commented Apr 24, 2018
- mingliao commented Apr 24, 2018 — with CMTY
- mingliao commented Apr 24, 2018 — with CMTY
- gomezmark commented Apr 25, 2018
- SnooHD commented Apr 25, 2018
- gomezmark commented Apr 26, 2018 •
- SnooHD commented Apr 26, 2018 — with CMTY
- gomezmark commented Apr 27, 2018
- SnooHD commented Apr 27, 2018 — with CMTY
- forteleaf commented Jul 4, 2018 •
- begueradj commented Oct 25, 2018
- fanvyr commented Dec 26, 2018
- begueradj commented Dec 26, 2018
- metadeck commented Feb 13, 2019
- This comment was marked as off-topic.
- eiva commented May 16, 2019
- begueradj commented May 16, 2019
- eiva commented May 16, 2019 •
- Как получить axios baseUrl в nuxt?
- 6 ответов
Set baseURL in interceptors is not working. #949
Comments
Baoyx007 commented Jun 9, 2017
set baseURL in interceptors is not working.
- axios version: e.g.: v0.16.2
- Environment: e.g.: node vv8.0.0, chrome 59.0.3071.86, macOS 10.12
The text was updated successfully, but these errors were encountered:
mrerhuo commented Jun 20, 2017
look me Custom instance defaults axios.all is not a function #948 my working normal only all is not a function
hectim commented Jun 23, 2017
Experienced the same issue. It might be more of a conceptual issue than an implementation detail. Seems to me that setting a baseURL is a way of saying «prepend this to every request», which seems kind of pointless when you set it on every request. Although a case could definitely be made for a conditional like:
But it doesn’t work. Setting a global default like this does:
axios.defaults.baseURL = ‘https://example.com’;
as does passing a config with the request:
axios.post(‘/extra’, < baseURL: 'https://example.com' >)
In both cases the ‘url’ field of the config is ‘https://example.com/extra’, but setting the baseURL in the interceptor only updates ‘config.baseURL’. I mean it makes sense why, you’re literally just updating that field, but it would be nice if it updated the url field as well or at least mentioned in the docs (preferably in big bold lettering) that setting baseURL in an interceptor is useless/not recommended.
@Baoyx007 you can always just change the ‘url’ value in the config manually
Источник
baseURL settings do not take effect for axios #171
Comments
begueradj commented Oct 25, 2018 — with CMTY •
Version
Reproduction link
Steps to reproduce
- Clone my repo and change to the resulted directory
- Intall the dependencites: yarn install
- Launch the server: yarn run dev
What is expected ?
expect the number of displayed posts to be 100.
This means in pages/index.vue , when I have this code:
axios should recoginize the baseURL configuration key I set in nuxt.config.js and thus fetch data from http://jsonplaceholder.typicode.com/posts
Here is my nuxt.config.js file content related to axios module:
What is actually happening?
The number of displayed posts is 0
axios is trying to send a get request to http://localhost/posts instead of http://jsonplaceholder.typicode.com/posts
The text was updated successfully, but these errors were encountered:
aldarund commented Oct 25, 2018 — with CMTY
Its not a bug. You are import fresh instance of axios instead of using this.$axios
It clearly described in docs how you should use it
https://axios.nuxtjs.org/usage
cmty bot commented Oct 25, 2018
This bug-report has been cancelled by @aldarund.
begueradj commented Nov 4, 2018
@aldarund I guess I misued it, you are right. I wonder if you have time to tell me briefly if there are differences between using the 2 options (in terms of performance). Thank you
aldarund commented Nov 4, 2018
no, there wont be difference in terms of performance
sangdth commented Feb 27, 2019
It does not work in my case even when I used $axios
In .vue components, if I called process.env.apiUrl it will return «http://localhost:8000» which is correct as expected. But if I call this.$axios.defaults.baseURL it will be empty.
marko-mlinarevic commented Mar 9, 2019
it doesn’t work at mine also
mandaputtra commented Mar 31, 2019
Just remember to do npm run dev again after change settings -_-
begueradj commented Mar 31, 2019 •
This is what worked for me @marko-mlinarevic and I believe it should work for you too:
sangdth commented Mar 31, 2019
I do believe it should work in that way. I just don’t understand why sometimes it does not work. That’s why we came here to report.
miyarappo commented Apr 6, 2019 •
Hi! I was able When you are doing
begueradj commented Apr 8, 2019
@shrishankit During the installation of your nuxt application, you chose axios. So just open the file called nuxt.config.js in the home directory of your project and complete the axios settings (baseURL in your case) there.
This comment was marked as off-topic.
dlodeprojuicer commented Apr 24, 2019 •
This was My mistake was I was overriding the initial axios.baseURL value set in nuxt.config.js with a none existing store.state.api_url value in my axios interceptors script. Silly mistake but worth noting
DerekCrosson commented May 27, 2019
@shrishankit During the installation of your nuxt application, you chose axios. So just open the file called nuxt.config.js in the home directory of your project and complete the axios settings (baseURL in your case) there.
If only it was this easy.
skewness commented Oct 15, 2019
it worked for me adding require(‘dotenv’).config() to the nuxt.config.js
genu commented Dec 18, 2019
@skewness This worked for me as well..
I think the docs should be clear about this. They just say «They can be customized with API_PREFIX, API_HOST (or HOST) and API_PORT (or PORT) environment variables.»
which is not true, unless the .env file is loaded. unless it means passing in the env variables as arguments? ¯_(ツ)_/¯
begueradj commented Dec 19, 2019
You can make a pull request for that 😄 @genu
pawel-marciniak commented Apr 23, 2020
Is this still the case? Should I add require(‘dotenv’).config() on top of nuxt.config.js to enable .env variables?
mandaputtra commented Apr 24, 2020
@pawel-marciniak yes, if you want to use dotenv use it like that
trainoasis commented Dec 3, 2020
This is what worked for me @marko-mlinarevic and I believe it should work for you too:
unfortunately does not work. tried all options here 😀
johnson329 commented Jan 29, 2021
my problem is i used baseURI,it should be baseURL
f**k
pi0 commented Feb 1, 2021
baseUrl support added by 2.13.0 to avoid this again for others.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Setting baseURL in default configuration #175
Comments
nathanharper commented Dec 15, 2015
In some cases my app requires different defaults from the standard ones, and I’ve been dealing with this by putting something like this in the app’s entry point:
My tests are run in Node and I want to override the baseURL so that axios will work with Nock even with relative URLs, but the code above doesn’t work. Would it be reasonable to add this parameter to the defaultConfig when instantiating Axios? Or is there a better way I should be doing this? I have an example of what I mean here.
The text was updated successfully, but these errors were encountered:
mzabriskie commented Dec 17, 2015
This sounds like a bug. I will have to dig in a bit deeper to confirm, but at a glance the code looks problematic. The Axios constructor holds onto a defaultConfig for each instance. Which means that if axios.defaults ever changes the default instance won’t be modified.
nickuraltsev commented Dec 17, 2015
@mzabriskie Right, but what’s the point in making defaults «mutable»? If you need to use custom config, you can just pass it to the Axios constructor.
nathanharper commented Dec 17, 2015
@nickuraltsev But in that case every time you require axios you would need to call the constructor with the baseURL option, right? I was hoping for a way to override the defaults for my entire project.
mzabriskie commented Dec 17, 2015
I agree that config should be immutable for custom instances, but for the default axios instance changes to axios.default should change the config internally held by that instance.
To resolve this I think the defaults should be passed to the Axios constructor for the axios instance. Then change to axios.defaults = axios.defaultConfig so that modification will actually mean something.
nickuraltsev commented Dec 17, 2015
@mzabriskie That makes sense. There are some differences between the structure of defaults and config though. For example:
nickuraltsev commented Dec 17, 2015
@nathanharper One solution is to create a small module like this:
and then use this new module in your code instead of requiring axios directly:
mzabriskie commented Dec 21, 2015
@nickuraltsev you’re correct that there is a difference between defaults and config . However axios.defaults should effect the config of the default axios instance in the case that no config is provided to override defaults. The problem with the current implementation is that defaultInstance = new Axios() is called the first time axios = require(‘axios’) is called, before any chance is allowed to override axios.defaults . In this case axios.defaults should be mutable to allow developer to override default config.
nickuraltsev commented Dec 21, 2015
@mzabriskie What if don’t merge the defaults and defaultConfig in the constructor? We can merge the defaults , defaultConfig , and the request config in the request method instead. Thoughts?
Источник
base url is not working #134
Comments
gomezmark commented Apr 23, 2018 •
please help me
on my nuxt.config.js
and for my actions
but for the request
it request on the localhost
http://localhost:3000/verify/phone
The text was updated successfully, but these errors were encountered:
SnooHD commented Apr 23, 2018 — with CMTY •
Are you sure environment.API_URL is set correctly?
If it returns undefined , this would be the expected behaviour.
gomezmark commented Apr 24, 2018
On the top,
I declared it
mingliao commented Apr 24, 2018 — with CMTY
why dont you set this env in nuxt.config.js like this:
and use just like these:
mingliao commented Apr 24, 2018 — with CMTY
and what I saw you declare the param with a space。
*api location *with a space
gomezmark commented Apr 25, 2018
this is my full nuxt.config.js
and for axios plugins/axios
- im trying where i could add the base url XD
SnooHD commented Apr 25, 2018
You should declare your baseURL without []
If you want to use it in a plugin, you can read more about how to use the env property here:
https://nuxtjs.org/api/configuration-env/
Personally i just directly set the baseUrl in nuxt.config.js for Axios like so:
gomezmark commented Apr 26, 2018 •
Yes. without the brackets. I just indicate the bracket for example url.
Sorry for the confusion.
but for store
It looks like this
SnooHD commented Apr 26, 2018 — with CMTY
If you do not use arrow functions, you can access axios from this:
This way you do not have to use axios as a plugin.
gomezmark commented Apr 27, 2018
Thank you!
It’s working now. 🙂
I need some advice with this one
I set the cookie
but when executing the getUserDetails the token was null
on my plugins/axios
Am i doing right?
SnooHD commented Apr 27, 2018 — with CMTY
Why are you not using this.$auth.loginWith ??
It sets the token and cookie for you, then fetches and sets the user details (on this.$auth.user ).
Check the example!
forteleaf commented Jul 4, 2018 •
begueradj commented Oct 25, 2018
@forteleaf That is the issue: the owner of the post sees that axios sends GET requests to localhost instead of the URL he defined with baseURL configuration key. And actually I have the same issue (I opened a bug about it)
fanvyr commented Dec 26, 2018
@begueradj got the same issue. do you have a solution for that?
begueradj commented Dec 26, 2018
The solution I opted for was just to declared the URL variable on the page I needed. I know this is not clean, but that is the deal with Nuxt.js @fanvyr
metadeck commented Feb 13, 2019
Just double check that the variable is named baseURL rather than baseUrl . That one got me for a while.
This comment was marked as off-topic.
eiva commented May 16, 2019
Why it could not automatically guess base url, like just axios doing itself?
I can have service deployed in different environments(hosts): so how should I set «baseURL» to work with this?
begueradj commented May 16, 2019
Well, the bug issuer did not write baseUrl . So is the case with most other contributors here, but they faced the bug.
In my case, I can not reproduce this issue anymore, but I remember I faced it in previous Nuxt.js versions
eiva commented May 16, 2019 •
But actually, I have this problem. As a begginer in nuxt, I tried to use nuxt-axios and it does not work. I spent time looking on how to configure it if I dont have «hardcoded» host.
And I failed.
This is more strange that if I use just axios — it works out of the box.
Maybe somebody knows how to make nuxt-axios work in such situations?
Upd:
Actually, I found the solution:
Источник
Как получить axios baseUrl в nuxt?
У меня есть модуль axios в моем проекте Nuxt.js.
Я также настроил свой baseUrl (для API) в localhost:4040/api , когда мой клиент работает на порте 3000.
Когда я получаю данные изображения в API, он возвращает относительный путь к серверу API, например, «/upload/1.png»
< " ЦСИ " : " / загрузки / 1.png " >
Итак, мне нужно получить axios baseUrl и связать его с ним, чтобы получить полный путь к изображению.
Есть ли способ сделать это кроме жесткого кодирования?
6 ответов
Если в nuxt.config.js вы определили:
Все, что вам нужно сделать для изображения, это указать на него следующим образом:
Вы можете получить доступ к конфигурации Axios следующим образом, чтобы получить базовый URL API:
У меня была аналогичная проблема. Мой шаг разрешения выглядит следующим образом: Удалить папку .nuxt + удалить кэш в браузере Changer
Работает как положено. До этого я пробовал много способов, таких как уроки сообщества, но неэффективных.
Вы можете установить базовый URL для Axios
Поэтому в следующий раз этот URL будет добавлен с вашим необходимым путем для вызова API
Подробности смотрите ниже по ссылке
Если кто-то намеревается вызвать axios, позвоните через диспетчер store / index.js
Файл модуля member.js
Файл nuxt.config.js конфиг с Axios API
Извините, если ответ не подходит, но кто-то должен надеяться, что это их объясняет
В случае, если кому-то интересно, как сделать axios baseURL независимым от домена:
Источник