angular / angular/angular-cli

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

Offen Anfängerfreundlich
#33,955 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: @angular/build gemini-triaged
Vorherrschende Sprache
TypeScript
Sterne
27k
Forks
11.8k
Ø Merge
14 Std. 23 Min.
Gemergte PRs (30 T.)
162

Beschreibung

### 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?)

```bash
ng serve myproject --allowed-hosts "example.com"
```
"**Error: Unknown argument: example.com**"

Workaround:

```bash
__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

```diff
"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:
- https://github.com/angular/angular-cli/issues/13656
- https://github.com/angular/angular-cli/pull/15366

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

```text

```

### Your Environment

```text
-
```

### Anything else relevant?

_No response_

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Vergleiche packages/angular/build/src/builders/dev-server/schema.json mit packages/angular_devkit/build_angular/src/builders/dev-server/schema.json und konzentriere dich auf die Definitionen von allowedHosts sowie die damit verbundene Verarbeitung der dev-server-Optionen. Bestätige die beabsichtigte Kompatibilität mit dem bestehenden disableHostCheck-Verhalten und überprüfe anschließend, dass @angular/build:dev-server über die CLI ein Array von Hostnamen akzeptiert, ohne die unterstützte all-hosts-Option zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript, vite
Bereich
build-system, cli
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
74/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.