dev: false "reachable from the network" warning when `devServer.host` is a `*.localhost` subdomain

未关闭 适合新手
#1,644 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #1649 来自 @paoValle —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
cli, networking

调研方向

找到listen的实现,以及使用LOOPBACK_HOSTS.has(hostname)并触发警告和Network:提示的两处检查。阅读这些检查,并查找覆盖主机分类或开发服务器输出的现有测试。在这两处都将.localhost子域视为回环地址;当它们不再触发网络警告,也不再显示为网络 URL 时,即完成。

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

描述

Environment
  • @nuxt/cli: 4.0.1
  • nuxt: 4.6.2
  • Node.js: 24.21.0
  • OS: macOS
Reproduction
// nuxt.config.ts
export default defineNuxtConfig({
  devServer: { host: 'my-app.localhost' },
})
nuxt dev
Describe the bug

The CLI prints:

The dev server is reachable from the network without authentication: anyone who can connect can read the app, build errors and source code.

The server is not reachable from the network. my-app.localhost resolves to loopback only (dns.lookup('my-app.localhost', { all: true }) returns ::1 and 127.0.0.1), so the listener is bound to loopback just like with localhost.

Per RFC 6761 §6.3, localhost and every name under .localhost resolve to loopback. Browsers resolve them that way without DNS and treat them as secure contexts. *.localhost names are a common way to run several local apps side by side.

Cause

In listen the warning only checks an exact-match set:

const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1'])
// ...
if (announce && (anyHost || !LOOPBACK_HOSTS.has(hostname))) logger.warn('The dev server is reachable from the network ...')

my-app.localhost is not in the set, so it is treated as a public host. The same check also drives the Network: hint shown under the URLs.

Suggested fix

Treat any .localhost name as loopback, e.g.:

const isLoopbackHost = host => LOOPBACK_HOSTS.has(host) || host.endsWith('.localhost')

and use it in both places that currently call LOOPBACK_HOSTS.has(hostname).

Workaround

Leave devServer.host unset and pass --publicURL http://my-app.localhost:3000 to nuxt dev, so the CLI shows that URL without the warning.

主要语言
TypeScript
星标
402
派生
125
平均合并
2 天 9 小时
30 天内合并 PR
37

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

nuxt/cli 的其他 Issue

查看 nuxt/cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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