I'm currently developing a web application using vue.js for the front end and node.js for the server. Vue is running on port 8080 and Node.js is running on port 3001. To make API calls, I have set up a proxy in my vue.config.js file, but it doesn't seem to be working as expected.
Here's the code snippet from my vue.config.js:
module.exports = {
devServer: {
proxy: {
'^/api': {
target: 'http://localhost:3001',
ws: true,
secure: false
}
}
}
}
Below is the script from my Home page component where I use axios to call the API:
import axios from 'axios'
export default {
data () {
return {
categories: []
}
},
created () {
axios.get('/api/v1/categories')
.then(res => {
debugger
this.categories = res.data
})
}
}
As a beginner with vue.js, I'm not sure what's causing the issue.
EDIT This is the error I am encountering:
Proxy error: Could not proxy request /api/v1/categories from localhost:8080 to http://localhost:3001/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).