Angular 7中的URL连接错误

问题描述 投票:1回答:1

当我导航到项目中的其他页面时,控制台显示错误URL的404错误。这是它的样子:

https://localhost:4420/example.com/api/customers

虽然看起来像:

https://example.com/api/customers

当我以example.com api为目​​标时,我在项目中没有指定使用localhost:4220 api。

这是我的环境。

export const environment = {
  production: false,
  baseUrl: 'example.com/',
  apiUrl: 'example.com/api/'
};

以下是我如何使用该服务:

export class CustomersComponent implements OnInit  {
  customers: any;

  constructor(private http: HttpClient) { }

  ngOnInit() {
    const token = localStorage.getItem('jwt');
    this.http.get(environment.apiUrl + 'customers', {
      headers: new HttpHeaders({
        'Authorization': 'Bearer ' + token,
        'Content-Type': 'application/json'
      })
    }).subscribe(response => {
      this.customers = response;
    }, err => {
      console.log(err);
    });
  }
}

如果我从上面的代码中删除environment.apiUrl +,我得到

请求网址:http://localhost:4220/customers

所以从哪里来的部分“localhost:4420 /”和它连接在哪里?

angular typescript url-routing
1个回答
1
投票

尝试改变环境。使用https协议的文件,如下所示 -

export const environment = {
  production: false,
  baseUrl: 'https://example.com/',
  apiUrl: 'https://example.com/api/'
};
© www.soinside.com 2019 - 2024. All rights reserved.