Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #8513
Closed
Open
Issue created Feb 19, 2020 by Administrator@rootContributor

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

Created by: breathe

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
    })
  );
};
Assignee
Assign to
Time tracking