2

I have a React app created using create-react-app and I'm setting up a custom proxy for the API with this setupProxy.js:

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

module.exports = function (app) {
  app.use("/api", createProxyMiddleware({
      target: "http://lvh.me:8000/",
      changeOrigin: true,
    })
  )
}

and it doesn't work. On the terminal it shows this error:

[HPM] Error occurred while proxying request lvh.me:3000/api/v1/me/ to http://lvh.me:8000/ [ENOTFOUND] (https://nodejs.org/api/errors.html#errors_common_system_errors)

but if I change it to localhost:

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

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

it does work. Any ideas why?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622

0 Answers0