Skip to content

Node adapter in middleware mode doesn't work with serverless-http #16820

@james-yeoman

Description

@james-yeoman

Astro Info

Astro                    v6.3.6
Node                     v24.13.0
System                   Linux (x64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

(copied from the readme in my reproduction repo)

Astro seems to assume that if req.body exists, it's either a string, or it's been parsed by
some middleware from whichever server framework the IncomingMessage came from. See here

Serverless-http however, makes ctx.req.body a buffer. So it gets caught in the typeof req.body === 'object' clause. See here and here

So what ends up happening, is rather than the buffer just being passed through, it gets JSON-stringified, and the action payload ends up being {type: "Buffer", data: [...]}, which causes an AstroActionInputError.

What's the expected result?

Astro should have a branch to pass through buffers in makeRequestBody in packages/astro/src/core/app/node.ts

Link to Minimal Reproducible Example

https://github.com/james-yeoman/astro-node-serverless-bug

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)pkg: nodeRelated to Node adapter (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions