HonoH
Hono17mo ago
1 reply
./xehbit.sh

c.env.incoming already piped with an await?

It's an issue i've been trying to solve for a few months now, when running this example it wont print the "Hello" text to the console, however, when removing the commented line or removing the zValidator will print the "Hello" to the console. Is the c.env.incoming already being read somewhere else?

import { HttpBindings, serve } from '@hono/node-server';
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { z } from 'zod';

const http = new Hono<{ Bindings: HttpBindings }>();

http.post('/example', zValidator('query', z.object({ name: z.string() })), async (c) => {
  await new Promise<void>((resolve) => setTimeout(() => resolve(), 1)); // Removing this line prints "Hello" to the console.

  c.env.incoming.pipe(process.stdout);

  return c.json({ message: 'Hello, World!' }, 200);
});

serve({
  fetch: http.fetch,
  hostname: 'localhost',
  port: 1337,
});



###
POST http://localhost:1337/example?name=test HTTP/1.1
content-type: application/octet-stream

Hello
Was this page helpful?