Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from react-script 3.3.1 to react-scripts 3.4.0 required changing setupProxy #8513

Closed
breathe opened this issue Feb 19, 2020 · 4 comments

Comments

@breathe
Copy link

breathe commented Feb 19, 2020

Not 100% sure why -- but after upgrading to react-scripts 3.4.0 it became necessary for me to change the way that I'm requiring the http proxy ...

The instructions from here -- https://create-react-app.dev/docs/proxying-api-requests-in-development/ -- fail with 'proxy is not a function'

I had to change this code (which was working before ...):

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

const setupBackend = require("./setupBackend");
const target = setupBackend();

module.exports = function(app) {
  console.log("Setting up proxy url's on development server");

  app.use(
    ["/token_api", "/__meta_request"],
    proxy({
      target,
      changeOrigin: true,
      preserveHeaderKeyCase: false
    })
  );
};

To this:

const proxy = require("http-proxy-middleware").createProxyMiddleware;

const setupBackend = require("./setupBackend");
const target = setupBackend();

module.exports = function(app) {
  console.log("Setting up proxy url's on development server");

  app.use(
    ["/token_api", "/__meta_request"],
    proxy({
      target,
      changeOrigin: true,
      preserveHeaderKeyCase: false
    })
  );
};
@breathe breathe changed the title Upgrading from react-script 3.3.1 to react-scripts 3.4.0 required setupProxy Upgrading from react-script 3.3.1 to react-scripts 3.4.0 required changing setupProxy Feb 19, 2020
@partynikko
Copy link

Your two examples are identical. Did you accidentally paste the same code twice?

@breathe
Copy link
Author

breathe commented Feb 19, 2020

@partynikko oops I did ... edited.

The original code I had to change used the default export off of the http-proxy-middleware ...

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

const setupBackend = require("./setupBackend");
const target = setupBackend();

module.exports = function(app) {
  console.log("Setting up proxy url's on development server");

  app.use(
    ["/token_api", "/__meta_request"],
    proxy({
      target,
      changeOrigin: true,
      preserveHeaderKeyCase: false
    })
  );
};

@partynikko
Copy link

partynikko commented Feb 19, 2020

This has nothing to do with CRA but with http-proxy-middleware package. They just released a new major version introducing breaking changes like the one you are referring to.

Could it be that you probably upgraded that package and confused it with the update of react-scripts?

@hjr3
Copy link
Contributor

hjr3 commented Feb 19, 2020

https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually is now wrong due to the breaking changes in http-proxy-middleware.

I opened #8515 to fix.

@lock lock bot locked and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants