Skip to content

Instantly share code, notes, and snippets.

@dominictobias
Created April 1, 2019 15:49
Show Gist options
  • Save dominictobias/9fd97c6a839c79a88f1d3beeb515e5b2 to your computer and use it in GitHub Desktop.
Save dominictobias/9fd97c6a839c79a88f1d3beeb515e5b2 to your computer and use it in GitHub Desktop.
setupProxy.js for http->https with cookies
const proxy = require('http-proxy-middleware');
// Execute `copy(document.cookie)` in the console on the proxy site
// and paste into this string.
const cookies = '';
module.exports = function(app) {
app.use(proxy('/api', {
changeOrigin: true,
cookiePathRewrite: true,
cookieDomainRewrite: true,
secure: false,
rejectUnauthorized: false,
onProxyReq: (proxyReq, req, res) => {
proxyReq.setHeader('Cookie', cookies);
},
target: 'https://proxysite.com/',
}));
};
@satyendrasingh092
Copy link

Thanks for code snippet . I have tried the above code but it was giving error. Then i fixed that error with following piece of code.

  app.use(
    proxy('/api', {
      changeOrigin: true,
      cookieDomainRewrite: {
       "unchanged.domain": "unchanged.domain",
       "old.domain": "new.domain",
      "*": ""
      },
      secure: false,
      rejectUnauthorized: false,
      onProxyReq: (proxyReq, req, res) => {
        proxyReq.setHeader('Cookie', cookies);
      },
      target: 'https://proxysite.com/'
    })
  );
};```

Setting boolean true for cookiePathRewrite and cookieDomainRewrite  is not working.
https://www.npmjs.com/package/http-proxy-middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment