Axios concatenate baseURL with localhost
See original GitHub issueHello everyone! 😄
Im having an issue when making requests from axios, thats happen in very different ways, but basically, it concatenate my baseURL with localhost, i found an similiar issue described here on a stackoverflow post
Somethings that i tried:
- Reinstall the project (Removing e installing node_modules again)
- Create a new Quasar Project, selecting Axios as a needed dependencie, and with axios dont selected too
- Tried axios with Import, with boot (By Quasar), importing, creating an axios instance and exporting
Codepen/jsFiddle/Codesandbox (required) https://codepen.io/nicolaslima321/pen/poPmRGY
To Reproduce I had 3 different ways to reproduce this error, but basically, its just do a axios request with baseURL setted:
1º -> When i create an axios instance and use it through my JS imports:
const api = axios.create({ baseURL: `${process.env.API_URL}/` })
export default api;
....
import api from './axios' (example)
api.post('/somepath')
2º -> When i static change axios.defaults.property:
axios.defaults.baseURL = apiUrl
axios.post('/somepath')
3º -> When i booted axios by Quasar following it docs, using it directly in a Vue component:
Example (considering my boot/axios.js) axios.js:
import { boot } from 'quasar/wrappers'
import axios from 'axios'
const api = axios.create({ baseURL: `${process.env.API_URL}/` })
export default boot(({ app }) => {
app.config.globalProperties.$axios = axios
app.config.globalProperties.$api = api
})
export { api }
Component.vue:
The result for two options is the same.
this.$api.post('/somepath')
this.$axios.post('/somepath')
Expected behavior Do a request considering only the baseURL with nothing concatenated
Screenshots
(When i do a post request) with this code return axios.post('/api/users', { user });
Platform (please complete the following information): Quasar Version: 2.0.3 @quasar/app Version: 3.0.0
Quasar mode:
- SPA
- SSR
- PWA
- Electron
- Cordova
- Capacitor
- BEX
Tested on:
- SPA
- SSR
- PWA
- Electron
- Cordova
- Capacitor
- BEX
OS: Ubuntu 20 Node: v14.15.4 NPM: 6.14.10 Yarn: Not using Browsers: Chrome iOS: Not using Android: Not using Electron: Not using
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top GitHub Comments
No, it was solved when you added : after https and before //
@pdanpdan Our request is based on the website’s own domain name to request the interface, for example, the corresponding API request of a.com is a.com/api, the corresponding API request of b.com is b.com/api, Found unavailable windos.localhost.host and process.env.api_url in boot/axios.js
Process.env. API_URL can be used in the development environment but not in the production environment
Is there any way to configure automatic domain name acquisition for the current site in boot/axios.js