Git Product home page Git Product logo

awesome-create-react-app's Issues

Notes on using proxy feature with remote https api

I wanted to share some notes on using the CRA proxy feature to use a remote https api - whether that's a qa api, staging, or prod/production

  1. Start server HTTPS=true WSS=true npm start | cat
  2. open https://localhost:3000

Use these options in setupProxy.js (with http-proxy-middleware)

    secure: false, // without this we get [HPM] Error occurred while trying to proxy request /login?use-proxy=1 from localhost:3005 to https://qa.site.com (ERR_TLS_CERT_ALTNAME_INVALID) (https://nodejs.org/api/errors.html#errors_common_system_errors) and 500 in chrome ?use-proxy xhr
    changeOrigin: true,
    logLevel: 'debug',
    preserveHeaderKeyCase: true,
    target: 'https://qa.site.com',
    ws: true,
    // cookieDomainRewrite: ourLocalhostHostname,
    onProxyReq: function relayRequestHeaders(proxyReq, req) {
        Object.keys(req.headers).forEach(function (key) {
            proxyReq.setHeader(key, req.headers[key]);
        });
    },
    onProxyRes: function relayResponseHeaders(proxyRes, req, res) {
        Object.keys(proxyRes.headers).forEach(function (key) {
            res.append(key, proxyRes.headers[key]);
        });
    },

If you want to use charles proxy to observe the requests - see this: http://marianna.im/tech/capture-nodejs-traffic-with-charles/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.