Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
angular, typescript, vite
領域
build-system, cli

調査の方向性

packages/angular/build/src/builders/dev-server/schema.json と packages/angular_devkit/build_angular/src/builders/dev-server/schema.json を比較し、allowedHosts の定義と、それに関連する dev-server オプションの処理に重点を置いてください。既存の disableHostCheck の動作との意図された互換性を確認し、そのうえで、@angular/build:dev-server が CLI 経由でホスト名の配列を受け入れ、サポートされている all-hosts オプションを壊さないことを検証してください。

索引モデルが issue の本文から書いたものです。

説明

area: @angular/build gemini-triaged
Command

serve

Is this a regression?
  • Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was

No response

Description

When using @angular-devkit/build-angular:dev-server I can use --allowedHosts parameter with array of hostnames, so my hostnames can be dynamic.

But when using @angular/build:dev-server the array of names is not recognized (only boolean type is passed instead?)

ng serve myproject --allowed-hosts "example.com"

"Error: Unknown argument: example.com"

Workaround:

__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=example.com ng serve myproject

or hard code in the array format in angular.json like mentioned in https://github.com/angular/angular/issues/64104

Comparing the two builder i can see this difference if you "patch" @angular/build:dev-server's schema.json, then the command will work.

https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/builders/dev-server/schema.json
vs
https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/dev-server/schema.json

    "allowedHosts": {
+     "type": "array",
      "description": "The hosts that the development server will respond to. This option sets the Vite option of the same name. For further details: https://vite.dev/config/server-options.html#server-allowedhosts",
      "default": [],
+      "items": {
+        "type": "string"
+      }
-      "oneOf": [
-        {
-          "type": "array",
-          "description": "A list of hosts that the development server will respond to.",
-          "items": {
-            "type": "string"
-          }
-        },
-        {
-          "type": "boolean",
-          "description": "Indicates that all hosts are allowed. This is not recommended and a security risk."
-        }
-      ]
    },

@see issue * PR for the devkit commit that added the option:

It note that @angular-devkit/build-angular:dev-server also has a (custom?) --disableHostCheck parameter which sets allowedHosts to true if passed, so then disable all hosts situation can be covered as schema no longer allows boolean, only array.

Not sure how to fix properly.

Minimal Reproduction
Exception or Error

Your Environment
-
Anything else relevant?

No response

主要言語
TypeScript
スター
27k
フォーク
11.8k
平均マージ
16時間 21分
マージ済み PR(30日)
170

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

angular/angular-cli のほかの issue

angular/angular-cli の issue をすべて見る

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

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