2

I made my setupProxy.js to deal with a CORS issue:

const proxy = require('http-proxy-middleware');

module.exports = function (app) {
    app.use(
        proxy('/myUrl', {
            target: 'http://localhost:8090',
            changeOrigin: true
        })
    )
};

After I made it and run 'npm start' again, my browser says that localhost refuses to connect. If I delete setupProxy.js, I can connect to localhost, but the CORS policy blocks to connect with backend server.

Do you have any idea to connect to frontend, still using the setupProxy.js?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Comet
  • 63
  • 2
  • 8

3 Answers3

2

You can try this: createProxyMiddleware

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

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

https://stackoverflow.com/a/60354374/11652543

Panu
  • 21
  • 3
0

See that you have spelled the name of setupProxy.js well that solved the problem for me. If that does not work. Copy and pase the fb's code the way it is into the setupProxy.js Code can be found here

0

I had the same issue.

For me the problem was that I added "type": "module" in my package.json which seems to be unsupported.

user1119279
  • 331
  • 3
  • 9