3

Why do I got this error:

Proxy error: Could not proxy request /api/v1/management/me from localhost:3000 to http://localhost:8080 (ECONNREFUSED).

Got this axios setting:

axios.defaults.baseURL = "http://localhost:3000/";

And set this in package.json:

"proxy": "http://localhost:8080"

tried also:

"proxy": "http://localhost:8080/"

And have following call:

axios({
  method: "get",
  url: "api/v1/management/me",
  data: {},
  headers: { crossDomain: true },
})

When I call directly http://localhost:8080/api/v1/management/me I got response from server.

I have following backend, Vapor route setting. Maybe something wrong / specific here?

let protectedAPIRouter = authSessionRouter.grouped("api/v1").grouped(User.guardAuthMiddleware())
let managementAPIRouter = protectedAPIRouter.grouped("management")
2

3 Answers 3

3

I would suggest the following solutions:

  1. Try to change localhost to IP address: "proxy": "http://your_IP_address:8080"
  2. Try this construction also:
"proxy": {
    "/api/*":  {
      "target": "http://localhost:8080",
      "secure": false
    }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

I had the same problem and it worked after setting 127.0.0.0 instead of localhost
2

I solved this issue change localhost to 127.0.0.1 in the package.json over the client project.

Comments

0

You need to set up a proxy to the backend service you want to access.

  1. First install (http-proxy-middleware) package.
  2. Remove the ("proxy": "http://localhost:8080/") or the Url behind the proxy in the package json file.
  3. In the src folder create a file (setupProxy.js) and and the following code.

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:8080',
      changeOrigin: true,
    })
  );
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.