1

I have a React application and I'm adding the http-proxy-middleware.

My goal is to redirect all the requests to /recipes and /users to my new proxy middleware, so I added to the app.js the following lines of code:

import { createProxyMiddleware } from 'http-proxy-middleware';

const setupProxy = () => {
    return createProxyMiddleware(['/recipes','/user'], {target: 'http://localhost:3001'});
}

But when I run, I receive an error 404.

The browser logger says

[HPM] Proxy created: /recipes,/user  -> http://localhost:3001
xhr.js:187 GET http://localhost:3000/recipes 404 (Not Found)

It looks like it completely ignore the middleware!

Without the http-proxy-middleware, but with only the "proxy": "http://localhost:3001", statement in package.json the application runs without problems.

Any idea?

Paolo Di Pietro
  • 517
  • 3
  • 17
  • I also have this issue, has this been resolved? Any suggestions please? – user923499 Feb 14 '22 at 06:19
  • Well, I resolved this issue by myself. I used a completely different approach: I defined `REACT_APP_APP_SERVER='https://www.yyy.com'` in my `.env` file, then I use that info into the code to create the reference address: `const { REACT_APP_APP_SERVER } = process.env; const parms1 = REACT_APP_APP_SERVER + path;` Then I added `CORS` to my application server: `const cors = require('cors') router.use(cors()) ` It solved the problem. – Paolo Di Pietro Feb 14 '22 at 11:43

0 Answers0