proxyReqBodyDecorator does not pass modified body
proxy.js
const express = require('express')
const proxy = require('express-http-proxy');
const bodyParser = require('body-parser');
const multer = require('multer');
const app = express();
var upload = multer();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api',upload.single('file'), proxy('localhost:4000', {
proxyReqBodyDecorator: function(bodyContent, srcReq) {
bodyContent.file = srcReq.file;
console.log(JSON.stringify(bodyContent));
return bodyContent;
},
proxyReqPathResolver: function(req) {;
return require('url').parse(req.url).path;
}
}));
api.js
const express = require('express')
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
router.post('/uploadfile', async function(req, res){
console.log(req);
});
This is my code to proxy to localhost:4000
From console.log(JSON.stringify(bodyContent)) of proxy.js , I can see the correct bodyContent which I had modified. However, in api.js, I still receive empty body inside req. proxyReqBodyDecorator does not pass the modified proxyReqBodyDecorator
Result of console.log(JSON.stringify(bodyContent)) from proxy.js
{"file":{"fieldname":"image","originalname":"152545959171533975.png","encoding":"7bit","mimetype":"image/png","buffer":{"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13,73...}
Result of console.log(req.body) from api.js
{}
Method calling API: with POST and form-data body
same for me
it's a long shot but did you @eljefedelrodeodeljefe or @holopekochan find a solution for this issue without rebuilding it with a different package like http-proxy-middleware?