Skip to content

Instantly share code, notes, and snippets.

@ravi123shanker
Created January 7, 2021 12:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ravi123shanker/f054bf0d5f6f7d3db772858aebf109d7 to your computer and use it in GitHub Desktop.
Save ravi123shanker/f054bf0d5f6f7d3db772858aebf109d7 to your computer and use it in GitHub Desktop.
How to Configure a Webpack Proxy for HTTPS domain
Step 1:
Add below line in your start script command in package.json
"start": "webpack-dev-server --https --env.apiBaseUrl='https://yourdomain.com/' --config webpack.config.js"
Step 2:
After above changes, change your webpack.config.js as below:
module.exports = function({ apiBaseUrl = "https://yourdomain.com/" }) {
return {
...
devServer: {
...
proxy: {
"/api": {
"changeOrigin": true,
"cookieDomainRewrite": "localhost",
"target": apiBaseUrl,
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', apiBaseUrl);
}
}
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment