Skip to content
GitLab
    • Explore Projects Groups Snippets
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
  • Merge requests
  • !3845

Replace advanced proxy with user provided proxy.js (#3366)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/iansu/proxy-js into next 7 years ago
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: iansu

Remove "advanced proxy" object from package.json, replace with user provided proxy.js.

Closes #3366 (closed)

Approval is optional

Closed by (Jul 25, 2025 5:43am UTC)

Loading

Activity


  • Administrator added CLA Signed label 7 years ago

    added CLA Signed label

  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: iansu

    Work in progress on new proxy.

    TODO

    1. Figure out what exactly needs to be passed to user function to generate proxy config. Everything being passed now might not be necessary or there might be a better way to pass it (config object?)
    2. Possibly reload app when proxy.js changes (this is probably very difficult as the proxy is part of the webpack dev server config
    3. Clean up comments and error messages
    4. Test various proxy configs
  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: iansu

    This is the proxy.js I'm using for testing:

    module.exports = function(paths, resolveLoopback, mayProxy, onProxyError) {
      let target;
      if (process.platform === 'win32') {
        target = resolveLoopback('http://localhost:8000');
      } else {
        target = 'http://localhost:8000'
      }
    
      return [
        {
          path: '/api/**/*',
          target,
          logLevel: 'silent',
          context: function(pathname, req) {
            return (
              req.method !== 'GET' ||
              (mayProxy(pathname) &&
                req.headers.accept &&
                req.headers.accept.indexOf('text/html') === -1)
            );
          },
          onProxyReq: proxyReq => {
            // Browers may send Origin headers even with same-origin
            // requests. To prevent CORS issues, we have to change
            // the Origin to match the target URL.
            if (proxyReq.getHeader('origin')) {
              proxyReq.setHeader('origin', target);
            }
          },
          onError: onProxyError(target),
          secure: false,
          changeOrigin: true,
          ws: true,
          xfwd: true
        }
      ];
    };
  • Administrator mentioned in issue #3366 (closed) 7 years ago

    mentioned in issue #3366 (closed)

  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: FezVrasta

    I don't think this allows to proxy the root path, right?

    I'd like to proxy the root path and serve the CRA from a sub directory

    I have described how to make it work here:
    https://github.com/facebookincubator/create-react-app/issues/3366#issuecomment-356349994

  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: DonnyVerduijn

    Any progress on this?

  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: yyfearth

    @iansu As I commented on the #3366 (closed) I suggest to put the filename proxy.js into the proxy config of the package.json. So the filename do not have to be hardcoded, and user have the freedom to chose other names.

  • Administrator mentioned in issue #4086 (closed) 7 years ago

    mentioned in issue #4086 (closed)

  • Administrator
    Administrator @root · 7 years ago
    Author Contributor

    Created by: ng-parth

    Any updates? Any idea if this PR is going to be accepted?

  • Administrator closed 6 years ago

    closed

  • Administrator reopened 6 years ago

    reopened

  • Administrator
    Administrator @root · 6 years ago
    Author Contributor

    Created by: iansu

    Closing this as it was superseded by #5073

  • Administrator closed 6 years ago

    closed

Please register or sign in to reply
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
CLA Signed
1
CLA Signed
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: facebook/create-react-app!3845
Source branch: github/fork/iansu/proxy-js

Menu

Explore Projects Groups Snippets