nodejs / nodejs/node

Add http.serve() API based on Fetch (Request -> Response)

未关闭
#63,096 8 条评论 38 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request http
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

What is the problem this feature will solve?

Node provides fetch, Request/Response, and Web Streams, but no high level server API using this model.

Other runtimes such as Deno and Bun expose a serve API based on the Fetch contract. In Node, similar patterns are commonly implemented in userland (e.g., frameworks like Hono), which indicates demand for this abstraction.

This was discussed in #42529 and received support, however that issue is focused on request.toWeb(), so opening a separate issue focused on this API.

What is the feature you are proposing to solve the problem?

Add a high-level http.serve(handler) API.

An example shape could be:

http.serve((req) => new Response("ok"))

handler: (Request) => Response | Promise<Response>

This would coexist with the existing http.createServer, and be a high level alternative using WHATWG APIs instead.

What alternatives have you considered?
  • Continue using http.createServer directly.
  • Implement this in userland, or use existing 3rd party solutions.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看 Node 现有的 http.createServer API 以及 issue #42529 中的讨论。拟议的工作是使用 Request 和 Response 定义并添加 http.serve(handler),同时保留 createServer 可用。完成的标准是 API 的形式和行为已达成一致、完成实现,并覆盖同步和异步 handler。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
backend-api-design
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。