Skip to content
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

Cannot return Buffer when ETag middleware is used #186

Closed
marvinruder opened this issue Aug 12, 2024 · 3 comments · Fixed by #188
Closed

Cannot return Buffer when ETag middleware is used #186

marvinruder opened this issue Aug 12, 2024 · 3 comments · Fixed by #188

Comments

@marvinruder
Copy link
Contributor

When running the code

import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { etag } from 'hono/etag'

const app = new Hono()
app.use(etag())
app.get('/', (c) => c.body(Buffer.from('Hello Hono!')))
serve({ fetch: app.fetch })

and running curl localhost:3000, the server crashes:

node:internal/buffer:961
    super(bufferOrLength, byteOffset, length);
    ^

TypeError: Cannot perform Construct on a detached ArrayBuffer
    at new Uint8Array (<anonymous>)
    at new FastBuffer (node:internal/buffer:961:5)
    at Function._uint8ArrayToBuffer (node:stream:144:10)
    at _write (node:internal/streams/writable:477:22)
    at Writable.write (node:internal/streams/writable:508:10)
    at ServerResponse._writeRaw (node:_http_outgoing:443:17)
    at ServerResponse._send (node:_http_outgoing:420:15)
    at write_ (node:_http_outgoing:1018:15)
    at ServerResponse.end (node:_http_outgoing:1102:5)
    at responseViaResponseObject (/Users/mruder/git-repos/hono-buffer/node_modules/@hono/node-server/dist/index.js:392:16)
@yusukebe
Copy link
Member

@marvinruder Thank you for rasing the issue. This seems to be a @hono/node-server bug.

Hey @usualoma, if you have a time, can you take a look?

@usualoma
Copy link
Member

I'll fix it, just wait a minute.

@marvinruder
Copy link
Contributor Author

Works fine now in 1.12.1, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants