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

我们两清 提交于 2019-11-30 12:35:06

问题


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

}

回答1:


You can deploy a CORS Anywhere server to Heroku in literally 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 instead with your own proxy’s URL.



来源:https://stackoverflow.com/questions/47076743/cors-anywhere-herokuapp-com-not-working-503-what-else-can-i-try

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!