IONIC 3 CORS ISSUE

后端 未结 7 2403
小蘑菇
小蘑菇 2020-12-09 18:16

I am having a CORS issue with Ionic 3 when attempting to make GET calls to an API. I am using Ionic local server, running ionic serve in the command line for li

7条回答
  •  难免孤独
    2020-12-09 18:37

    To fix this issue, please change the following lines

    ionic.config.json

    {
      "name": "projectLeagueApp",
      "app_id": "47182aef",
      "type": "ionic-angular",
      "integrations": {
        "cordova": {}
      },
      "proxies": [
        {
          "path":"/games",
          "proxyUrl": "https://api-2445582011268.apicast.io/games"
        }
      ]
    }
    

    You have to remove the " / " which is at the end of of "proxyUrl".

    My Data Service

    return this.http.get('/games/?fields=name,release_dates,screenshots&limit='+this.limit+'&offset='+offset+'&order=release_dates.date:desc&filter[genres][eq]='+genre_id+'&filter[screenshots][exists]', this.options)
    

    In the http call, the url should begin with '/games'. '/games' because ionic will proxy http://localhost:/games to https://api-2445582011268.apicast.io/games

    Please use the above method for external GET and POST calls in your application.

    Thank you.

提交回复
热议问题