I set up Ionic proxy to resolve Cors errors but its not working, what am I doing wrong?












0















I read the documentation from ionic and when I run serve it shows that a proxy is set up but it's not changing the url (in the console I get "Http failure response for http://localhost:8100/v1/profile/pc/Playername: 401 Unauthorized"). I tried every solution I found for this problem but nothing works for me. What am I missing here ?



Here is my ionic.config.json file:



{
"name": "myApp",
"integrations": {
"cordova": {}
},
"type": "ionic-angular",
"typescript": true,
"proxies": [
{
"path": "/v1/profile/",
"proxyUrl": "https://api.sitetitle.com/v1/profile/"
}
]
}


Here is the provider where I make the request:



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);
}

}


And here is my 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": {}
}
}
}









share|improve this question



























    0















    I read the documentation from ionic and when I run serve it shows that a proxy is set up but it's not changing the url (in the console I get "Http failure response for http://localhost:8100/v1/profile/pc/Playername: 401 Unauthorized"). I tried every solution I found for this problem but nothing works for me. What am I missing here ?



    Here is my ionic.config.json file:



    {
    "name": "myApp",
    "integrations": {
    "cordova": {}
    },
    "type": "ionic-angular",
    "typescript": true,
    "proxies": [
    {
    "path": "/v1/profile/",
    "proxyUrl": "https://api.sitetitle.com/v1/profile/"
    }
    ]
    }


    Here is the provider where I make the request:



    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);
    }

    }


    And here is my 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": {}
    }
    }
    }









    share|improve this question

























      0












      0








      0








      I read the documentation from ionic and when I run serve it shows that a proxy is set up but it's not changing the url (in the console I get "Http failure response for http://localhost:8100/v1/profile/pc/Playername: 401 Unauthorized"). I tried every solution I found for this problem but nothing works for me. What am I missing here ?



      Here is my ionic.config.json file:



      {
      "name": "myApp",
      "integrations": {
      "cordova": {}
      },
      "type": "ionic-angular",
      "typescript": true,
      "proxies": [
      {
      "path": "/v1/profile/",
      "proxyUrl": "https://api.sitetitle.com/v1/profile/"
      }
      ]
      }


      Here is the provider where I make the request:



      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);
      }

      }


      And here is my 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": {}
      }
      }
      }









      share|improve this question














      I read the documentation from ionic and when I run serve it shows that a proxy is set up but it's not changing the url (in the console I get "Http failure response for http://localhost:8100/v1/profile/pc/Playername: 401 Unauthorized"). I tried every solution I found for this problem but nothing works for me. What am I missing here ?



      Here is my ionic.config.json file:



      {
      "name": "myApp",
      "integrations": {
      "cordova": {}
      },
      "type": "ionic-angular",
      "typescript": true,
      "proxies": [
      {
      "path": "/v1/profile/",
      "proxyUrl": "https://api.sitetitle.com/v1/profile/"
      }
      ]
      }


      Here is the provider where I make the request:



      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);
      }

      }


      And here is my 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": {}
      }
      }
      }






      ionic-framework proxy cors






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 13:50









      SylarattySylaratty

      367




      367
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301798%2fi-set-up-ionic-proxy-to-resolve-cors-errors-but-its-not-working-what-am-i-doing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301798%2fi-set-up-ionic-proxy-to-resolve-cors-errors-but-its-not-working-what-am-i-doing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues