代码之家  ›  专栏  ›  技术社区  ›  user2094257

任何地方的cors。herokuapp。com不工作(503)。我还能试什么?

  •  13
  • user2094257  · 技术社区  · 7 年前

    我的代码:

    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'));
      }
    
    }
    
    3 回复  |  直到 5 年前
        1
  •  71
  •   sideshowbarker Miguel Tomás    3 年前

    您可以部署 任何地方的CORS 服务器到Heroku只需2-3分钟,有5个命令:

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

    任何地方的CORS 代理运行在,例如。 https://cryptic-headland-94862.herokuapp.com/ . 因此,不要在请求URL前面加前缀 https://cors-anywhere.herokuapp.com ,在其前面加上代理URL。

        2
  •  1
  •   Mike Q    3 年前

    对此,我想为Windows用户提供更详细的回应:

    Windows要求的项目

    完成以上所有操作后,发出以下命令

    打开一个新的终端,然后:

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

    它将处理和更新/上传,您将获得一个应用程序URL:

    https://some-name-giveng.herokuapp.com/
    
        3
  •  0
  •   Abdul Rehman    2 年前

    这是因为公共演示服务器(cors anywhere.herokuapp.com)在2021前受到限制 https://github.com/Rob--W/cors-anywhere/issues/301

    这是我自己的代理服务器

    https://fast-dawn-89938.herokuapp.com/

    您可以使用: https://fast-dawn-89938.herokuapp.com/https://your-domain.com

    https://fast-dawn-89938.herokuapp.com/https://google.com

    祝您今天过得愉快!