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?