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

オープン 初心者向け
#1,644 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #1649 @paoValle による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
cli, networking

調査の方向性

listenの実装と、警告およびNetwork:のヒントを出すLOOPBACK_HOSTS.has(hostname)を使った2つのチェックを見つけてください。そのチェックを読み、ホストの分類や開発サーバーの出力を対象とする既存のテストを探してください。両方の箇所で.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時間
マージ済み PR(30日)
37

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nuxt/cli のほかの issue

nuxt/cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。