vue dev server proxy not working

To configure proxy settings in a Vue.js development server, you can follow these steps:

  1. Open the vue.config.js file in the root directory of your Vue project. If the file doesn't exist, create it.

  2. Inside the vue.config.js file, add the following code:

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000', // Replace with your API server address
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}
  1. In the code above, we're configuring the Vue development server to proxy requests starting with /api to the specified target address, which is http://localhost:3000 in this example. You should replace this with the actual address of your API server.

  2. The changeOrigin option is set to true to add the Host header to the proxied request, which is necessary for some server configurations.

  3. The pathRewrite option allows you to rewrite parts of the URL path. In this example, we're removing the /api prefix from the request path before forwarding it to the target server.

  4. Save the vue.config.js file.

  5. Restart the Vue development server for the changes to take effect.

Now, when you make HTTP requests from your Vue app to URLs starting with /api, the development server will forward those requests to the specified target address.

Note: Make sure that you have the necessary dependencies installed for proxying to work properly. You can install the http-proxy-middleware package by running npm install http-proxy-middleware or yarn add http-proxy-middleware.

I hope this helps! Let me know if you have any further questions.