Error 429 Too Many Request when App is compiled

Hi there. I’m having a Error 429 once my app is compiled in my smartphone, I’m to expecting to solve this problem with the community:
´´´
x {headers: h, status: 429, statusText: “Too Many Requests”, url: “https://cors-anywhere.herokuapp.com/https://geolocate.herokuapp.com/users/”, ok: false, …}
´´´
In my navigator it works perfectly. With postman i tried to emulate that problem, sending various requests, and it works too. This only happens when i have my app compiled in my smartphone.

A solution that come up to my mind was whitelisting my endpoint in config.xml

  <allow-navigation href="*" />
    <allow-navigation href="https://cors-anywhere.herokuapp.com/https://geolocate.herokuapp.com/users/" />

Another solution was trying to define my platforms in order to make them work

<platform name="android">
        <preference name="android-minSdkVersion" value="19" />
        <preference name="android-targetSdkVersion" value="29" />
<platform/>

But my app doesn’t works when I try to make my request.

Testing Platform: Android 8.1.0
Development OS: Mac OS Catalina
Cordova Version: 9.0.0 (cordova-lib@9.0.1)
Ionic CLI version: 6.2.0

´´´
Ionic:

Ionic CLI : 6.2.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 4.11.9
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.1.2

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 6 other plugins)

Utility:

cordova-res : not installed
native-run : 0.3.0

System:

NodeJS : v12.16.1 (/usr/local/bin/node)
npm : 6.14.1
OS : macOS Catalina
Xcode : Xcode 11.3.1 Build version 11C504

´´´

A public demo of CORS Anywhere is available at https://cors-anywhere.herokuapp.com. This server is only provided so that you can easily and quickly try out CORS Anywhere. To ensure that the service stays available to everyone, the number of requests per period is limited, except for requests from some explicitly whitelisted origins.

Does the problem persist when using a proxy you host? The error message you describe looks to me to be consistent with a public demo instance trying to protect itself against abuse.

Hi rapropos. Thanks for your response, i deleted https://cors-anywhere.herokuapp.com in my endpoint. But when i do that I get the following error:

Access to XMLHttpRequest at ‘https://geolocate.herokuapp.com/users/’ from origin ‘http://localhost’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

But I always put that header in my service:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'

@Injectable({
  providedIn: 'root'
})
export class LocationService {
  httpOptions
  readonly url: string = 'https://geolocate.herokuapp.com/users/'
  constructor(
    private http: HttpClient
  ) { 
    this.httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': '*'
      })
    };
  }
  postLocation(bodyForm : object) {
    return this.http.post(this.url,bodyForm,this.httpOptions)
  }
  updateLocation(id: string,bodyForm : object) {
    return this.http.put( this.url + `${id}`, bodyForm, this.httpOptions)
  }
  getLocation() : any {
    return this.http.get( this.url, this.httpOptions)
  }
  searchLocation( term : object) {
    return this.http.get( this.url, this.httpOptions)
  }
}

Doesn’t matter. CORS needs to be fixed on the server side; that’s why the proxy idea works.

Thank you, I solved my problem i had to put this code in my server, in case if somebody had the same error.

let cors = require('cors')
app.use(cors())
1 Like