[Vuejs]-Why proxy in vue.config.js 404

0👍

So you are configuring Vue CLI dev-server (running on port 8001) to proxy all requests to /api to http://localhost:8080/blog/api (server) but at the same time configure Axios to use baseURL: process.env.VUE_APP_API_ADDRESS …which means Axios is sending all requests directly to your server instead of proxy…

Just remove that baseURL: process.env.VUE_APP_API_ADDRESS from Axios config

I also believe your pathRewrite option in proxy config is incorrect.

  1. You dispatch request to /dev-api/blog/lastBlogs
  2. Request goes to Vue dev-server (localhost:8001)
  3. Proxy translates /dev-api into http://localhost:8080/blog/dev-api = http://localhost:8080/blog/dev-api/blog/lastBlogs
  4. pathRewrite is applied to whole path part of the URL – /blog/dev-api/blog/lastBlogs – RegEx ^/dev-api will not match

Try to change pathRewrite into [process.env.VUE_APP_BASE_API]: '/api'

Leave a comment