angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

Can't be set '/' proxy path in Angular17 #26343

Closed cipchk closed 10 months ago

cipchk commented 10 months ago

Command

serve

Is this a regression?

The previous version in which this bug was not present was

No response

Description

Angular start fails when setting a '/' proxy path.

Screenshot:

image

It looks like Angular returns the proxy data directly after startup, but in fact proxyConfig should only be for HttpClient.

Minimal Reproduction

  1. Create new angular
  2. Add proxy.conf.json config:
{
  "/": {
    "target": "http://localhost:9103/",
    "secure": false,
    "changeOrigin": true,
    "headers": { "Connection": "keep-alive" }
  }
}
  1. Add "proxyConfig": "proxy.conf.json" in angular.json
"serve": {
  "configurations": {
        "development": {
+           "proxyConfig": "proxy.conf.json"
        }
  }
}
  1. Update app.config.ts
import {
  APP_INITIALIZER,
  ApplicationConfig,
  Injectable,
  inject,
} from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { HttpClient, provideHttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
class StartupService {
  private http = inject(HttpClient);

  load(): Observable<any> {
    return this.http.get('/');
  }
}

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideHttpClient(),
    StartupService,
    {
      provide: APP_INITIALIZER,
      useFactory: (startupService: StartupService) => () =>
        startupService.load(),
      deps: [StartupService],
      multi: true,
    },
  ],
};

Exception or Error

No response

Your Environment

Angular CLI: 17.0.0
Node: 18.16.0
Package Manager: yarn 1.22.19
OS: darwin x64

Angular: 17.0.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.0
@angular-devkit/build-angular   17.0.0
@angular-devkit/core            17.0.0
@angular-devkit/schematics      17.0.0
@angular/cli                    17.0.0
@schematics/angular             17.0.0
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else relevant?

No response

JoostK commented 10 months ago

It looks like Angular returns the proxy data directly after startup, but in fact proxyConfig should only be for HttpClient.

I don't know where this expectation comes from, but it does not align with my expectation. All traffic goes through the proxy server, so routing / to a different host will then cause all requests to be proxied as requested.

angular-automatic-lock-bot[bot] commented 9 months ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.