Proxy error with vue.config.js and axios

Hello, this is my vue.config.js

module.exports = {

devServer: {

  proxy: {

    '^/api': {

        target: 'http://localhost:3001',

        changeOrigin: true,

        secure:false,

        pathRewrite: {'^/api': '/api'},

        logLevel: 'debug' 

    },

 

  }

}

}

I can do get request with it but my post request gives an error like

[HPM] Rewriting path from “/api/staffs/” to “/api/staffs/”
[HPM] GET /api/staffs/ → http://localhost:3001/
[HPM] Rewriting path from “/api/staffs” to “/api/staffs”
[HPM] POST /api/staffs → http://localhost:3001/
Proxy error: Could not proxy request /api/staffs from localhost:8080 to http://localhost:3001/.
See Errors | Node.js v15.7.0 Documentation for more information (ECONNRESET).

Anyone knows how to fix it? I couldn’t fix it since days. I tried this, http://127.0.0.1:3001/ , other config options but none of them works.Im using vue cli 3 and express on my backend api

Did you ever figure this out? There was an issue with browsers updating today and enforcing “strict-origin-when-cross-origin” on all AJAX requests, which forced us to open CORS up on our development server (not an issue in prod as the back end/front end is hosted on the save port/server) and I can now hit all URLs by referencing the absolute path at http://localhost:5000, but if I try to use the Webpack proxy, as we’ve been using for years, I get the “Could no proxy request” error now…

I let that project away. I didn’t remember %100 but there was an typo error in another page, i fixed that and requests worked, warnings didn’t go away but it wasn’t affecting anything.

Hi, I encountered this problem, solved it by replacing localhost or 127.0.0.1 with [::1]
A few months later, i had to go back to 127.0.0.1…
Maybe did some process change my hosts file.

You should type ping localhost in your terminal in order to check your current configuration and use the result to set your proxy.