CORS Error for POST requests from localhost to BaseUrl in React

Viewed 22
  1. Install http-proxy-middleware
npm install http-proxy-middleware --save-dev or yarn add http-proxy-middleware --dev
  1. Create a file setupProxy.js in the /src folder
const { createProxyMiddleware, fixRequestBody } = require("http-proxy-middleware");

module.exports = app => {
    app.use(createProxyMiddleware('**', {
        target: 'https://...com',
        changeOrigin: true,
        secure: false,
        onProxyReq: fixRequestBody,
    }));
}
  1. Remove proxy and secure in the package.json (if any)
"proxy": "https://...com",
"secure": false
  1. Run npm/yarn start.
0 Answers
Related