request.formData()
doesn't resolve if it is read in Express middleware
#10132
-
Hello, I'm using a custom Express server with my Remix application and I have a middleware that captures some data from For that, I'm using import { createRemixRequest } from "@remix-run/express/dist/server.js";
import type { NextFunction, Request, Response } from "express";
export async function extractFormDataProp(req: Request, res: Response, next: NextFunction) {
const remixRequest = createRemixRequest(req, res).clone();
if (remixRequest.method !== "POST") {
next();
return;
}
const formData = await remixRequest.formData();
const propValue = formData.get("propName");
if (!propValue || typeof propValue !== "string") {
next();
}
req.prop = propValue;
console.log("extractFormDataProp", { propValue, reqProp: req.prop });
next();
} However, when the processing reaches the I'm using the following versions of the relevant dependencies:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The body of a request can only be read once, this is because the browser stream it so next time you want to read it it already ended the stream. Either don't read it on Express or pass the read body to Remix using getLoadContext. |
Beta Was this translation helpful? Give feedback.
The body of a request can only be read once, this is because the browser stream it so next time you want to read it it already ended the stream.
Either don't read it on Express or pass the read body to Remix using getLoadContext.