I have 3 services:
- A React app
- A Node express gateway
- A Node express backend
I send files from the React app to the backend using a proxy in the gateway. The thing is if express.json() or express.urlencoded() middlewares are set before the proxy the req.file is empty after multer encoded it.
Relevant code:
react app:
const formData = new FormData();
formData.append("file", file);
formData.append("type", "pdf");
formData.append("contentId", "srfewrgferg");
console.log(formData.get("file"));
axios.post( config.BASE_URL + "/activities/create", formData)
gateway:
const router = express();
router.use(express.json());
router.use(express.urlencoded({ extended: true }));
router.post("/activities/*", proxy( `${config.urlPresupuestos}/`, {
proxyReqPathResolver: ( req: Request ) => {
return req.originalUrl;
}
}));
backend:
const router = express();
router.use(multerMiddleware.single("file"));
router.post("/activities/create", (req, res) => {
console.log(req.file)
});
If I remove the express middlewares in the gateway all works fine, but I need those middlewares for other routes. Any suggestion why this could be happening?