Open krutoo opened 1 year ago
Can you show how the request looks like
@preveen-stack not quite understand what the request means?
If not, how to properly use the http package and convert IncomingMessage to Request and use the Response to send response in the handler of createServer function? the "Request" you mentioned in the issue
@preveen-stack global Node.js constructors Request and Response from Fetch API:
new Request('http://site.com', { method: 'POST' });
new Response('Not found', { status: 404 });
This seems like a pretty nice thing for Node.js to have. I'm trying to write these conversion methods myself but it's easy to mis something 😅 could this be a rework of createServer
Stumbled upon this while looking for solutions on how to use itty-router with node.js. Found this so far https://www.npmjs.com/package/@whatwg-node/server ... but it says it ponyfills, which is better than polyfilling, but it still does too much magic for my liking
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
@bra1nDump @whatwg-node/server
is great, thanks
But it looks like a little tricky solution and i dont think this is get great performance
Details
I want to create basic HTTP server with Node.js. I also want to declare request handler based on Fetch API like this:
Are there any built-in packages to achieve this?
If not, how to properly use the
http
package and convertIncomingMessage
toRequest
and use theResponse
to send response in the handler ofcreateServer
function?Node.js version
18+
Example code
Here is my naive implementation of the
serve
function. I have several quetions about it:Operating system
macos
Scope
runtime
Module and version
Not applicable.