Thanks for a good work on open source.
I am using node-server to run a very simple web page, but I encounter the error Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close quite often. After investigating alternative servers, I discovered that miniflare is also aware of this issue and they don't use pipeline(..) in their implementation. You can see their implementation at https://github.com/cloudflare/miniflare/blob/7e4d906e19cc69cd3446512bfeb7f8aee3a2bda7/packages/http-server/src/index.ts#L215-L241.
Although miniflare works well, it is quite heavy. In order to have a stable and smooth runtime, I think we should follow miniflare's approach in this implementation.
My code
async function mainFetch(req: Request, _env: Record<string, string>): Promise<Response> {
const u = new URL(req.url);
if (u.pathname === '/favicon.ico') {
// seems like issue went here
return fetch('https://my-internal-site/favicon.ico');
}
return new Response('OK');
}
serve(
{
fetch(r) {
return mainFetch(r, {});
},
port: 3535,
},
(info) => console.log(`http://localhost:${info.port}`)
);
Run the complied code and access the webpage.
$ node dist/index.cjs
http://localhost:3535
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
at new NodeError (node:internal/errors:399:5)
at ServerResponse.onclose (node:internal/streams/end-of-stream:154:30)
at ServerResponse.emit (node:events:525:35)
at emitCloseNT (node:_http_server:965:10)
at Socket.onServerResponseClose (node:_http_server:277:5)
at Socket.emit (node:events:525:35)
at TCP.<anonymous> (node:net:322:12) {
code: 'ERR_STREAM_PREMATURE_CLOSE'
}
CC: @yusukebe
Thanks for a good work on open source.
I am using
node-serverto run a very simple web page, but I encounter the errorError [ERR_STREAM_PREMATURE_CLOSE]: Premature closequite often. After investigating alternative servers, I discovered thatminiflareis also aware of this issue and they don't usepipeline(..)in their implementation. You can see their implementation at https://github.com/cloudflare/miniflare/blob/7e4d906e19cc69cd3446512bfeb7f8aee3a2bda7/packages/http-server/src/index.ts#L215-L241.Although
miniflareworks well, it is quite heavy. In order to have a stable and smooth runtime, I think we should followminiflare's approach in this implementation.My code
Run the complied code and access the webpage.
CC: @yusukebe