question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios concatenate baseURL with localhost

See original GitHub issue

Hello 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 }); image

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:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
pdanpdancommented, Aug 17, 2021

No, it was solved when you added : after https and before //

0reactions
gh81997167commented, May 11, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

React App URL and Backend URL are getting concatenated ...
You need to set a proper base URL for axios: ... try { const url = "http://localhost:4000/pets/cats"; ... An example using base URL:...
Read more >
Setting baseURL in default configuration · Issue #175 - GitHub
My tests are run in Node and I want to override the baseURL so that axios will work with Nock even with relative...
Read more >
Complete Guide to Axios HTTP Client - Reflectoring
In this example, we are using axios.create() to create a new instance of Axios with a custom configuration that has a base URL...
Read more >
Axios Tutorial: Get/Post/Put/Delete request example - BezKoder
We can create a new instance of axios using axios.create(config) method. const instance = axios.create({ baseURL ...
Read more >
How to get the full URL in ExpressJS ? - GeeksforGeeks
Step to run the application: Open the terminal and type the following command. · Output: · Explanation: When we enter any Url in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found