Proxying APIs for Vue.js application

Proxying APIs for Vue.js application

Backend API endpoint - https://reqres.in/api

This is my demo application:

And, this is how my network calls look like:

Now, after proxying the APIs, Request URL should become http://localhost:8080/api/users

Since I am using Axios in main.jsI had to put this line of code:

axios.defaults.baseURL = 'http://localhost:8080/api/'

Then, create vue.config.js file at the root level, and put below code in there.

module.exports = {
   devServer: {
      proxy: 'https://reqres.in'
   }
}

restart dev server. — npm run serve

Leave a Reply

Your email address will not be published. Required fields are marked *