首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置sawtooth explorer时被CORS策略问题阻止

设置sawtooth explorer时被CORS策略问题阻止
EN

Stack Overflow用户
提问于 2020-01-18 12:03:57
回答 1查看 188关注 0票数 0

我使用this guide设置了sawtooth seth。在设置sawtooth seth之后,我尝试将其连接到sawtooth-explorer。sawtooth seth和sawtooth explorer都在docker上成功运行。但是sawtooth explorer和sawtooth seth没有连接。我收到以下cors策略阻止错误。

代码语言:javascript
复制
Access to XMLHttpRequest at 'http://localhost:8080/transactions?limit=10' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
explorer.component.ts:210 Error fetching items from API (transactions):  

帮我修复这个错误。

EN

回答 1

Stack Overflow用户

发布于 2020-03-11 13:29:49

如果您尝试通过sawtooth explorer获取事务,您将在Docker容器中收到来自Nginx的"Bad Gateway 502“错误。

为了解决您的CORS问题传递http proxy,您需要在您的nginx.conf文件中定义端口,将GET请求发送到您的nginx在Docker容器中的端口。

例如,如果您的锯齿rest-api连接到端口8024,那么您可以配置Sawtooth explorer-rest-api- proxy,以便在您的nginx.conf文件中使用端口8024来传递http代理。

以下是rest-api的docker-compose.yaml文件的摘录

docker-compose.yaml

代码语言:javascript
复制
rest-api:
    image: hyperledger/sawtooth-rest-api:1.0
    container_name: supply-rest-api
    expose:
      - 8008
    ports:
      - '8024:8008'
    depends_on:
      - validator
    entrypoint: |
      sawtooth-rest-api -vv
        --connect tcp://validator:4004
        --bind rest-api:8008

锯齿资源管理器在docker文件夹中有相关的nginx配置。

nginx.conf

代码语言:javascript
复制
    server {
        listen 8090;
        add_header Pragma no-cache always;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, OPTIONS';
        add_header Access-Control-Allow-Headers 'X-XSRF-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';

        location / {
          #proxy_pass http://localhost:8008;
          proxy_pass http://192.168.3.10:8024;
          proxy_read_timeout 5000;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59797442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档