The Axios patch method encounters an issue where the baseURL is not retrieved

I have encountered a problem while trying to update the base URL in my Axios patch request. Despite specifying the new baseURL in the stageReceiver method, it continues to use the default baseURL (which is set when running npm serve).


import axios from "axios";

const getSingleSenders = baseURL =>
  axios
    .get("/single/senders", {baseURL: baseURL})
    .then(({ data }) => ({ senders: data }))

const stageReceiver = (receiverId, baseURL, stagedPayload) =>
  axios
    .patch("/single/receivers/" + receiverId + "/staged", {
        baseURL: baseURL,
        payload: stagedPayload,
        Headers: {"Content-Type": "application/json"}
      })
    .then(({ data }) => ({ receiver: data }))

export default {
    getSingleSenders,
    getSingleSender,
    stageReceiver
};

Even after calling the function with a newBaseURL parameter like "http://172.17.0.13:8080/test":

const stagedResult = await connectionService.stageReceiver(id, newBaseURL, connectionPayload) 

The browser shows a 404 error with an incorrect URL pointing to my Vue dev instance at localhost:

http://localhost:8082/single/receivers/id/staged

Instead of:

The issue does not occur with the getSingleSenders method, where the baseURL is correctly used. I am unsure about what I am missing and would appreciate any guidance on this matter.

Answer №1

To correctly configure your setup, you should pass the config as the third parameter according to the documentation provided:

const stageReceiver = (receiverId, baseURL, stagedPayload) =>
    axios
      .patch(
         "/single/receivers/" + receiverId + "/staged",
         stagedPayload,
         {
            baseURL: baseURL,
            Headers: { "Content-Type": "application/json" }
         }
      )
      .then(({ data }) => ({ receiver: data }));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modify the element within the Vuex store array upon modification of the component

Within my Vuex store, there exists an array of Notes, with each individual Note being represented by a <textarea>. I have a component called NoteArray that is responsible for displaying each Note: // NoteArray.vue export default { name: "NoteA ...

I possess 9 captivating visuals that gracefully unveil their larger counterparts upon being clicked. Curiously, this enchanting feature seems to encounter a perplexing issue within the realm of web browsing

<style type="text/javascript" src="jquery-1.11.0.min.js"></style> <style type="text/javascript" src="myCode.js"></style> </body> //jquery is within my site directory on my desktop $(document).ready(function(){ //note: $("#ar ...

While working with AJAX, the variable value remains static and is not refreshed

My jQuery code successfully calls a REST Service and handles the response in the AJAX Success event. However, I'm facing an issue where the variable "SelectedVal" (document.getElementById('Text1').value) is not getting updated with each cli ...

tips on displaying textbox content on a php webpage

I have a piece of code where, when text is entered into a textbox and the add attribute button is clicked, the entered value is displayed on the page twice. One appears in the first row of a table, and the other appears in the first row of a second table. ...

Our system has picked up on the fact that your website is failing to verify reCAPTCHA solutions using Google reCAPTCHA V2

Error Message We have noticed that your website is not validating reCAPTCHA solutions. This validation is necessary for the correct functioning of reCAPTCHA on your site. Please refer to our developer site for further information. I have implemented the re ...

JavaScript: Manipulating Data with Dual Arrays of Objects

//Original Data export const data1 = [ { addKey: '11', address: '12', value: 0 }, { addKey: '11', address: '12', value: 0 }, { addKey: '12', address: '11', value: 0 }, { addKey: &a ...

How to mock nested functions within sinon

There are several questions similar to this one, but none of them quite match the scenario I'm dealing with. The situation involves a function that takes another function as a parameter: var myfunc = (func_outer) => { return func_outer().func ...

Troubleshooting problems with AngularJS placeholders on Internet Explorer 9

On my partial page, I've included a placeholder like this: <input name="name" type="text" placeholder="Enter name" ng-class="{'error':form.name.$invalid}" ng-model="Name" required /> I have also set up client side validation for the ...

Is there a way to incorporate a text box in javascript that displays the retrieved reference count from the database?

I'm currently working on creating a functionality that retrieves rows with the same ID from a database and displays them in a text box. Below is the PHP code I've written for retrieving all the rows: PHP: <?php include_once('pConfig ...

Improving user input in AngularJS

My goal is to create a filter that converts time into seconds, such as: 01:30:10 becomes 5410, and vice versa. This way, the model only holds seconds while providing users with a more user-friendly representation. I've successfully implemented a work ...

The selected tag value does not appear to be updating in the v-model

When using v-model on the select tag, I noticed that it does not reflect any changes in the blade template. I conducted a test with an empty HTML file and found that it worked fine there. However, the issue only arises when I try to implement it in the bl ...

The Right Way to Set Up Form Data in VueJS

Currently, I am facing an issue with a component that renders a form and pre-fills the fields with data retrieved from an ajax request. The problem lies in my desire to edit existing fields and simultaneously add new fields for submission. To accomplish t ...

Adjust the background color of children based on the parent's mouseover event

Seeking a solution to fill three bars with varying percentages: <div class="bars" style="width:0%; background-color: red;"> <span class="bar"></span> <span class="bar"></span> <span class="bar"></span> </ ...

What is the best way to save characters from different languages into variables?

I created an application that reads words from a TXT file and stores them in a database. The issue arises when I encounter words from other languages that contain non-English characters, resulting in the following problem: Is it possible to store these ch ...

When utilizing a React styled component, it functions smoothly during development but triggers a build error when in production

Recently, I encountered a strange issue with my code. I have a styled component div that wraps around another component in this manner: <ContentWidget> <BookDay /> </ContentWidget> (The Bookday component returns an empty div so there ...

Tips on showcasing array elements within a table's tbody section and including several values within the same array

I am struggling to figure out how to display array values in my table rows that I receive from input values. I have created an array, but I can't seem to find a way to display them in the table. Furthermore, I want to be able to add more values to th ...

How should one go about creating an npm package out of a vuejs component and testing it locally?

Initially, I created a vuejs project as a test container using vue-cli. Next, I developed an npm package named "vue-npm-example" from a Vuejs component in my local environment and then imported it into the aforementioned testing project. Within the packag ...

Navigating routes for a module sourced from NPM: Best practices

Looking for guidance on loading Angular routes from an NPM module? Take a look at this snippet from my app.module.ts file: import { HelloWorldModule } from 'hello-world-app-npm/hello-world-app.umd.js'; // Loading module from NPM const routes = ...

Retrieve the value from an input field when the value is returned from JavaScript

Scenario: I'm currently working on creating a QR reader to retrieve a specific value. You can check out the progress here: What's functioning: scanning. When I scan a QR code, a value is displayed in the text box. Here's the code snippet b ...

State in React is not always defined when making a fetch request

Just started using React and encountered an issue while working on my fetch request: I am receiving a formatted response with Axios, but when I try to set the state using the same variable like this: setSelectedStatParams(formattedResponse), it shows up as ...