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

Đang mở Phù hợp với người mới
#33,955 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
angular, typescript, vite
Lĩnh vực
build-system, cli

Hướng nghiên cứu

So sánh packages/angular/build/src/builders/dev-server/schema.json với packages/angular_devkit/build_angular/src/builders/dev-server/schema.json, tập trung vào các định nghĩa allowedHosts và cách xử lý các tùy chọn dev-server liên quan. Xác nhận khả năng tương thích dự kiến với hành vi disableHostCheck hiện có, sau đó kiểm tra rằng @angular/build:dev-server chấp nhận một mảng tên máy chủ thông qua CLI mà không làm hỏng tùy chọn all-hosts được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 21 phút
Pull request đã merge (30 ngày)
170

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.