Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cors-anywhere.herokuapp.com not working (503). What else can I try?

I am trying to send a get request to the Wikipedia API. I am sending the request form a angular frontend so i'm trying to use the Heroku CORS Anywhere endpoint to avoid CORS issues. For some reason, I'm still getting a 503 response saying no access-control-allow-origin header is present on the requested resource. Any idea why this would happen/what else I can try?

My code:

import { Injectable } from '@angular/core';
import { Http, Response, } from '@angular/http';
import { Observable } from 'rxjs/Rx';



@Injectable()
export class RestService {
    API_URL: string = 'https://cors-anywhere.herokuapp.com/https://en.wikipedia.org/wiki/';

  constructor(private http: Http) { }

  public getRandomArticle() : Observable<any> {
        return this.http.get(`${this.API_URL}Special:Random`)
        .map((res: Response) => res.json())
        .catch((err: any) => Observable.throw(err || 'server error'));
  }

}
like image 1000
user2094257 Avatar asked Nov 02 '17 13:11

user2094257


People also ask

What is Cors anywhere Herokuapp com?

CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request. The url to proxy is literally taken from the path, validated and proxied. The protocol part of the proxied URI is optional, and defaults to "http".


2 Answers

You can deploy a CORS Anywhere server to Heroku in just 2-3 minutes, with 5 commands:

git clone https://github.com/Rob--W/cors-anywhere.git
cd cors-anywhere/
npm install
heroku create
git push heroku master

After running those commands, you’ll end up with your own CORS Anywhere proxy running at, e.g. https://cryptic-headland-94862.herokuapp.com/. So then instead of prefixing your request URL with https://cors-anywhere.herokuapp.com, prefix it with your proxy’s URL.

like image 136
sideshowbarker Avatar answered Oct 04 '22 19:10

sideshowbarker


In response to this I wanted to give a more detailed response for Windows users:

Windows Requried Items

  • Create Heroku account (heroku.com) Install the Heroku CLI (e.g. https://devcenter.heroku.com/articles/heroku-command-line) Install Git (e.g. https://gitforwindows.org/) Install npm tools (e.g. https://nodejs.org/en/download/)

After everything above is done, issue the following commands

Open a new terminal, then:

heroku login
git clone https://github.com/Rob--W/cors-anywhere.git
cd cors-anywhere/
npm install
heroku create
git push heroku master

It will process and update/upload and you will get a app URL:

https://some-name-giveng.herokuapp.com/
like image 24
Mike Q Avatar answered Oct 04 '22 19:10

Mike Q