Skip to content

toNodeHandler fails in Cloud Functions environment #139

@niklv

Description

@niklv

Environment

Cloud Functions (2nd gen)

"h3": "^2.0.1-rc.5" 

On [email protected] all works fine as expected.

Reproduction

This code with h3@v2 not work

import { onRequest } from 'firebase-functions/https'
import { H3, readBody } from 'h3'
import { toNodeHandler } from 'h3/node'

const app = new H3()

app.post('/', async event => {
  const body = await readBody(event) // stucks forever here
  return body
})

const nodeHandler = toNodeHandler(app)

export const app = onRequest(async (req, res) => {
  await nodeHandler(req, res)
})

This code with h3@v1 works.

import { onRequest } from 'firebase-functions/https'
import { createApp, createRouter, defineEventHandler, readBody, toNodeListener } from 'h3'

const app = createApp()
const router = createRouter()

router.post(
  '/',
  defineEventHandler(event => readBody(event))
)

app.use(router)

const nodeHandler = toNodeListener(app)

export const app = onRequest((req, res) => {
  nodeHandler(req, res)
})

Describe the bug

When try to read body from request it stucks until timeout.
After some debug i found that event.req.text() stucks too.
It leads to this code:
https://github.com/h3js/srvx/blob/main/src/adapters/_node/request.ts#L180-L195
As far as I debugged it, it does not fire any listners here.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions