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.

Setting baseURL in default configuration

See original GitHub issue

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:

let axiosDefaults = require('axios/lib/defaults');
axiosDefaults.baseURL = 'http://somesite.com';

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

146reactions
nickuraltsevcommented, Dec 17, 2015

@nathanharper One solution is to create a small module like this:

// client.js

var axios = require('axios');

var axiosInstance = axios.create({
  baseURL: 'https://domain.com/foo/bar',
  /* other custom settings */
});

module.exports = axiosInstance;

and then use this new module in your code instead of requiring axios directly:

var client = require('./client');

client.get('relative/path')
144reactions
rkmaxcommented, Mar 3, 2016

never mind! I realize I’m using the wrong property baseUrl instead baseURL

Read more comments on GitHub >

github_iconTop Results From Across the Web

Config Defaults | Axios Docs
Set config defaults when creating the instance const instance = axios.create({ baseURL: 'https://api.example.com' }); // Alter defaults after instance has ...
Read more >
Axios default configuration - how to set baseUrl and header ...
I am trying to set configure the axios with baseUrl and headers for each call. Is the following code correct? If I set...
Read more >
Configuring the base URL | Administering Jira applications ...
To configure the base URL: In the upper-right corner of the screen, select Administration > System. In the sidebar, select General ...
Read more >
Cleanly Setting Axios Base URL - YouTube
Want more? Explore the library at https://www.codecourse.com Official site … Show more. Show more. Key moments. View all. App Setup.
Read more >
38. Add Axios Default configuration like headers, base URL
In this video we will see how to add axios default configuration like headers, baseurl - Vue 3If you like my video, please...
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