I'm trying to change my Axios patch baseURL but I don't know why when I call this stageReceiver method it still getting a default baseURL (the one where my npm run serve is listening and serving my app).
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
};
When I call function when needed with lets say newBaseURL="http://172.17.0.13:8080/test":
const stagedResult = await connectionService.stageReceiver(id, newBaseURL, connectionPayload)
If I check on the browser I can see that the request is getting 404 with the wrong URL of my Vue dev instance (where my npm run serve is listening):
http://localhost:8082/single/receivers/id/staged
Instead
http://172.17.0.13:8080/test/single/receivers/id/staged
The other method getSingleSenders with get is working without any issue and it get the baseURL correctly written. I'm missing something but I don't know what. I hope the question is clear enough. Many thanks for any advice.
You should pass your config as third parameter as stated in the documentation:
const stageReceiver = (receiverId, baseURL, stagedPayload) =>
axios
.patch(
"/single/receivers/" + receiverId + "/staged",
stagedPayload,
{
baseURL: baseURL,
Headers: { "Content-Type": "application/json" }
}
)
.then(({ data }) => ({ receiver: data }));