当我导航到项目中的其他页面时,控制台显示错误URL的404错误。这是它的样子:
虽然看起来像:
当我以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 +
,我得到
所以从哪里来的部分“localhost:4420 /”和它连接在哪里?
尝试改变环境。使用https
协议的文件,如下所示 -
export const environment = {
production: false,
baseUrl: 'https://example.com/',
apiUrl: 'https://example.com/api/'
};