user13382723
user13382723

Reputation: 41

React http-proxy-middleware proxy not working

Hi I been trying the proxy solution to avoid the cors problems in myapp but it doesn't seem to work, i restarted my machine so many times and that made no difference. Basically myapp using fetchApi to call another domain (localhost:8080) which is a SpringBoot application endpoint. I added in package.json "proxy": "http://localhost:8080/" but the api still return calls with localhost:3000 and i tried setupProxy.js but i faced same issue....Am i missing anything else ! any help would be appreciated...

const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = function (app) {
  app.use(
    "/oauth",
    createProxyMiddleware({
      target: "http://localhost:8080",
      changeOrigin: true,
      secure: false,
      logLevel: "debug",
    })
  );
};

Upvotes: 3

Views: 1440

Answers (2)

Anas El-Bharawy
Anas El-Bharawy

Reputation: 11

i added in /src folder and named 'setupProxy.js'

i added in /src folder and named 'setupProxy.js'

Upvotes: 0

I removed the {} on createProxyMiddleware and it started working. Thanks

Upvotes: 1

Related Questions