Я читаю документацию от ionic, и когда я запускаю serve, он показывает, что прокси-сервер настроен, но он не меняет URL-адрес (в консоли я получаю «Http error response для http://localhost:8100/v1/profile/pc/Playername: 401 Unauthorized»). Я пробовал все решения, которые я нашел для этой проблемы, но у меня ничего не работает. Что мне здесь не хватает?
Вот мой файл ionic.config.json :
{
"name": "myApp",
"integrations": {
"cordova": {}
},
"type": "ionic-angular",
"typescript": true,
"proxies": [
{
"path": "/v1/profile/",
"proxyUrl": "https://api.sitetitle.com/v1/profile/"
}
]
}
Вот поставщик , к которому я обращаюсь:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
/*
Generated class for the PlayerProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class PlayerProvider {
//private apiUrl = 'http://localhost:8100';
//private apiUrl2 = 'https://api.sitetitle.com';
constructor(public http: HttpClient) {
}
getPlayerStats(platform, name) {
console.log(platform, name);
let headers = new HttpHeaders();
headers.append('Api-Key', 'myapikey');
return this.http.get('/v1/profile/' + platform + '/' + name, {headers: headers}).map(res => res);
}
}
А вот и мой package.json :
{
"name": "myApp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "~4.15.0",
"@ionic-native/splash-screen": "~4.15.0",
"@ionic-native/status-bar": "~4.15.0",
"@ionic/storage": "^2.2.0",
"cordova-plugin-whitelist": "^1.3.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "^3.2.0",
"@ionic/cli-plugin-proxy": "1.5.8",
"@ionic/lab": "1.0.12",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {}
}
}
}