cors-anywhere.herokuapp.com 无法正常工作(503),我还可以尝试什么?

yftpprvb  于 2022-11-13  发布在  其他
关注(0)|答案(3)|浏览(223)

我正在尝试向Wikipedia API发送一个get请求。我正在从一个角前端发送请求,因此我尝试使用Heroku CORS Anywhere端点来避免CORS问题。由于某种原因,我仍然收到一个503响应,说请求的资源上没有access-control-allow-origin头。知道为什么会发生这种情况吗?我还可以尝试什么?
我的代码:

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

}
iqih9akk

iqih9akk1#

您只需2-3分钟即可将 CORS Anywhere 服务器部署到Heroku,只需使用5个命令:

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

运行这些命令后,您将得到自己的 CORS Anywhere 代理,运行在,例如https://cryptic-headland-94862.herokuapp.com/。因此,不要将您的请求URL作为前缀https://cors-anywhere.herokuapp.com,而应将其作为前缀,使用您的代理的URL。

uinbv5nw

uinbv5nw2#

对此,我想给予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/
doinxwow

doinxwow3#

这是因为公共演示服务器(cors-anywhere.herokuapp.com)在2021年1月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

相关问题