1

I set my images inside the public/avatars and render them via <img src='avatars/my-image1.svg' />

my app run on : http://localhost:3001

it works fine, but since I added a proxy inside the package.json:

proxy: http://localhost:3000

the images return 404 (not found)

Does anyone have any idea how to fix it?

H.Hattab
  • 113
  • 10

1 Answers1

2

The solution was to set the proxy for the endpoint via src/setupProxy.js (not via package.json)

and place the following contents in it:

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
  app.use(
    '/your_api',
    createProxyMiddleware({
      target: 'http://localhost:3000',
      changeOrigin: true,
    })
  );
};

link: https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually

image of full instruction

H.Hattab
  • 113
  • 10
  • Hi, Do you know the syntax to add several rules to setupProxy.js ? should i add a module.exports line or only a app.use line or how do i write that? –  Jun 11 '22 at 07:42