Saturday 29 August 2020

Problems setting baseURL for Axios

Hello!I'm having a few problems using baseURL in Axios…When using Vue:Vue.prototype.$axios = axios.create({ baseURL: process.env.ROOT_API }) … this works.But in Node (14.7), this won't:const axios = require('axios') let instanceOfAxios = axios.create({ baseURL: process.env.ROOT_API, timeout: 1000 }) ... instanceOfAxios.post('/assets', { ... } … or these:axios.post(`${process.env.ROOT_API}/assets`, { ... } axios.post(process.env.ROOT_API + '/assets', { ... } Each time, I get the same error message:UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:80The actual value of process.env.ROOT_API is: http://localhost:3000I've also declared the instance in an external file and imported it, but the same problem persists.I'm using process.env.ROOT_API elsewhere in the application (and have been since the beginning of development) without a problem.Any ideas?

Submitted August 29, 2020 at 09:57AM by WayneSmallman

No comments:

Post a Comment