【发布时间】:2020-05-20 14:42:39
【问题描述】:
该项目只是一个没有使用服务器端语言的前端,我想从区块链图表中获取实时数据,我已经看到了类似问题和答案但在其他框架上的答案。没有为 angular 指定任何内容。我在 src 文件夹中创建了一个 proxy.conf.json 文件并添加了以下代码,但是当我检查浏览器时仍然得到同样的错误
{
"/api/*": {
"target": "http://localhost:3000",
"secure": false,
"logLevel": "debug"
}
}
我已将 proxy.conf.jason 文件添加到 angular.json 下的 serve 部分,但我仍然不断收到错误:
“从源 'http://localhost:4200' 访问 XMLHttpRequest 在 'https://api.blockchain.info/charts/transactions-per-second?timespan=5weeks&rollingAverage=8hours&format=json' 已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' 标头”
这是我的 ApiService 类:
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private httpclient : HttpClient ) { }
public dailychart(){
return this.httpclient.get('https://api.blockchain.info/charts/transactions-per-second?timespan=5weeks&rollingAverage=8hours&format=json');
}
}
【问题讨论】:
-
您的应用运行情况如何?这是构建和部署的版本吗?代理仅在开发中有效。
-
@zero298 我处于开发模式
标签: javascript html angular http