angular - Angular 7 中的错误 URL 连接
问题描述
当我导航到项目中的不同页面时,控制台显示 404 错误和错误的 url。这是它的样子:
虽然它应该看起来像:
当我以example.com
api 为目标时,我在项目中没有指定使用localhost:4220
api。
这是我的环境.ts:
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/'
};
推荐阅读
- android - 可以自动更新付费应用的价格 - Playstore
- asp.net - ASP.NET Core 从 Area 访问静态文件
- python-sphinx - 在 Github Pages 问题中发布从 sphinx 文档构建的网站
- python - Pandas - 跳过 numpy 数组中给出的行数
- node.js - Sequelize 不会将值插入到新添加的列中
- php - 用于创建用户的 Laravel 表单无法正常工作
- primeng - 如何在没有 multipart/form-data 的情况下使用 PrimeNG p-fileUpload?
- python - 在使用 ctypes 加载时,在 C 中嵌入 Python 解释器会导致段错误
- azure - Azure:从现有 VHD 创建 VM 提供 VMMarketplaceInvalidInput
- azure-active-directory - 在使用 Azure AD v2 进行身份验证的应用中嵌入 PowerBI