1

I'm trying to adapt an older React app to work like an MS-generated client app I created. The newer one uses http-proxy-middleware in a script file named setupProxy.js so I am trying to do the same in the other.

The thing is, I cannot see anywhere in the MS-generated app that someone is actually invoking this setupProxy.js script. Not in the code and not in the package.json. In fact, not one single file in the app refers to it anywhere that I can see.

Yet I know that it does get invoked because I've already needed to change it to make certain fetches work.

So how does this happen? Is that just some magic file name whose very presence ensures that it will get called? Or, when I move it over to the older app, do I have to change some configuration file somewhere to be sure that it gets called?

Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
Joe
  • 5,394
  • 3
  • 23
  • 54

1 Answers1

0

setupProxy.js is a file used to set up a proxy between your React development server and an API, to avoid CORS errors for example.

By how it's named, your development server calls it while making HTTP requests. It doesn't have any meaning for the deployed application.

Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
  • Thank you for replying. I do understand what it does. What I'm trying to understand is how it gets invoked. If I add the http-proxy-middleware module to my package.json does that somehow automatically trigger it to look for a file by that name and execute it at startup? I just don't understand how the code path is actually triggered. – Joe Jul 22 '23 at 12:52
  • Hi Joe, I see! All they say on the doc about that is *"Note: You do not need to import this file anywhere. It is automatically registered when you start the development server*". I think you would need someone who knows the involved packages and Webpack very well, like one of the maintainers. – Youssouf Oumar Jul 23 '23 at 06:26