Closed
Description
Checks
- I understand project setup issues should be asked on StackOverflow or in GitHub Discussions.
- I updated to latest
http-proxy-middleware
.
Describe the bug (be clear and concise)
Hi,
I'm developing a React application and I configured my setupProxy.js but it seems no body data is forwarded to the server in the proxied request. What could be the problem?
Step-by-step reproduction instructions
...
Expected behavior (be clear and concise)
Forward the request with the body to the target host
How is http-proxy-middleware used in your project?
[email protected] /*****/*****/*****/*****/*****/gymnasio-management-app
├── [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected] deduped
What http-proxy-middleware configuration are you using?
const {createProxyMiddleware, fixRequestBody} = require('http-proxy-middleware');
const bodyParser = require('body-parser')
module.exports = function(app) {
var restream = function(proxyReq, req, res, options) {
if (req.body) {
let bodyData = JSON.stringify(req.body);
proxyReq.setHeader('Content-Type','application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData)
proxyReq.end();
}
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(
'/api/*',
createProxyMiddleware({
target: 'https://<domain>/',
changeOrigin: true,
pathRewrite: {
'^/api/': '<path>'
},
logLevel:'debug',
onProxyReq: restream,
})
);
};
What OS/version and node/version are you seeing the problem?
macOS Big Sur v11.5.2
Node v16.13.2
Additional context (optional)
No response