-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Body already used issue with certain libraries #26
Comments
Thanks for reporting this finding. Elysia has built-in support for parsing Line 152 in a1c27e5
Elysia cannot determine whether the body property is being accessed or not. As a result, it pre-parses the body ( Here's a workaround to skip parsing: .all("/api/auth/*", betterAuthView, { parse: () => 1 }) Kinda blocked by elysiajs/elysia#1009 |
Thanks for the response. I don't quite follow what you're saying - this seems to be more localized to this library than other things. I'm getting the same issue on my GraphQL server - body is already used unless I disable this logger (there isn't an obvious way to pass Sorry if i'm not understanding things correctly - but is there no way this library can use |
For now I've just moved my graphql yoga server above the logger call:
|
We need to wait until the mentioned Elysia issue is resolved. If other plugins cause similar issues, you can work around it by adding a global parse-hook and manually handling parsing on the cloned request: import { Elysia, ParseError } from "elysia";
const plugin = new Elysia({ name: "plugin" })
.derive((ctx) => ({ plugin: ctx.body }))
.as("global");
new Elysia()
.onParse(({ request, contentType }) => {
const cloned = request.clone();
switch (contentType) {
case "application/json":
return cloned.json();
case "text/plain":
return cloned.text();
}
throw new ParseError();
})
.use(plugin)
.post("/", ({ request }) => request.bodyUsed)
.listen(3000); |
What versions are running?
What steps can reproduce the bug?
My server looks like this:
betterAuthView
is this:When a request goes to an auth route, I get a
ERR_BODY_ALREADY_USED
error. If I comment out this logger, it works fine. I'm not exactly sure what's going on, but the stacktrace of the error is on this line (in the better-auth libary):return await request.json();
So it seems like that library is trying to consume the request body but by that time this logger already has...
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: