aim:

首先咱们把 broswer 和 自己的api 连接起来(要显示出来自己的本地ipfs id)

my bugs

  • CROS

How to do cross-origin requests on IPFS

https://github.com/INFURA/tutorials/wiki/IPFS-and-CORS

参考: No 'Access-Control-Allow-Origin' header is present on the requested resource.'Ajax跨域访问解决方案

https://blog.csdn.net/zhoucheng05_13/article/details/53580683


No 'Access-Control-Allow-Origin' header is present on the requested resource.

当使用ajax访问远程服务器时,请求失败,浏览器报如上错误。这是出于安全的考虑,默认禁止跨域访问导致的。

在A网站中,我们希望使用Ajax来获得B网站中的特定内容。如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题。你可以理解为两个域名之间不能跨过域名来发送请求或者请求数据,否则就是不安全的。跨域访问违反了同源策略,同源策略的详细信息可以点击如下链接:Same-origin_policy;

总而言之,同源策略规定,浏览器的ajax只能访问跟它的HTML页面同源(相同域名或IP)的资源。

解决ipfs 的 cros 问题的方法

ctrl- c退出ipfs
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST", "OPTIONS"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'

result

final code for c1

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Course C Exercise</title>
<link href="../assets/style.css" rel="stylesheet" />
</head>
<body>
<header>
<h1><a href="../index.html">IPFS Camp 2019: Course C</a></h1>
</header>
<div id="exercises" class="grid">
<div id="exercise-1" class="exercise">
<h2>Exercise #1: Talking to remote HTTP API from JS</h2>
<p>1. Initialize API instance under <code>ipfs</code> variable</p>
<p>2. Execute <code>ipfs.id()</code> to see what is on the other end</p>
<p>3. If it works, you will see returned output below:</p>
<p>
<pre id="ipfsId">(result of "ipfs id" will appear here)</pre>
</p>
</div>
</div>
<div id="peerBoard-container"></div> <!-- TODO: Add a script tag loading the http-client browser bundle -->
<!-- https://github.com/ipfs/js-ipfs-http-client#in-a-web-browser --> <script src="https://unpkg.com/ipfs-http-client/dist/index.min.js"></script> <script>
// TODO: Create a ipfs-http-client instance and connect it to a remote daemon
// https://github.com/ipfs/js-ipfs-http-client#in-a-web-browser
const ipfs = window.IpfsHttpClient('/ip4/127.0.0.1/tcp/5001') const ipfsId = document.querySelector('#ipfsId')
// ipfsId.textContent = JSON.stringify(id, null, 2) // TODO: use the http client to find the remote daemon ID
// https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/MISCELLANEOUS.md#ipfsidcallback ipfs.id().then(id => ipfsId.textContent = JSON.stringify(id, null, 2))
</script>
</body>
</html>

ipfs camp course c demo exercise 1的更多相关文章

  1. Java设计模式--观察者模式到监听器

    观察者模式是对象的行为模式.又叫做发布-订阅模式.模型-视图模式.源-监听器模式. 抽象主题角色:主题角色将所有对观察者对象的引用到保存在一个集合里,每个主题都可以拥有任意数量的观察者.抽象主题提供一 ...

  2. Java数组倒置

    Java数组之    -- 数组倒置 方法一 :  package mytest; public class test2 { public static void main(String[] args ...

  3. Java数组最大值和最小值

    package com.mybatis.demo.exercise; /** * @author yinsenxin */ public class ArrayMaxAndMin { public s ...

  4. Conway's Game of Life: An Exercise in WPF, MVVM and C#

    This blog post was written for the Lockheed Martin Insight blog, sharing here for the external audie ...

  5. BZOJ1695 : [Usaco2007 Demo]Walk the Talk

    观察单词表可以发现: 对于长度为3的单词,前两个字母相同的单词不超过7个 对于长度为4的单词,前两个字母相同的单词不超过35个 于是首先$O(26*26*nm)$预处理出 s1[x][i][j]表示( ...

  6. Modelsim的demo入门教程

    写在前面的话学过MCU设计的朋友都知道,系统调试是多么的重要.而对于FPGA设计来说,仿真确实最重要的.一个完整的项目,必须有完整的仿真平台.有朋友说,按键仿真模型没法搞. 我只能说,你并不了解硬件及 ...

  7. IPFS星际文件系统

    IPFS星际文件系统(InterPlanetary File System)是去中心化文件系统,本文介绍IPFS节点软件系统安装,环境搭建等简介入门教程,及学习如何使用ipfs-api和Node.js ...

  8. 如何在基于Bytom开发过程中集成IPFS

    本文介绍了基于Bytom开发过程中集成IPFS. step1: 搭建bytom节点 比原相关资料:https://github.com/Bytom-Community/Bytom_Docs 搭建byt ...

  9. 使用ipns 解决ipfs 内容更新的问题

    ipds 可以使用dnslink 解决域名访问的问题,但是内容变更我们就会有新的hashid 解决方法我们可以使用ipns ,同时解决dnslink 解决域名的问题 环境准备 docker-compo ...

随机推荐

  1. 解决:配置虚拟主机,重启apache,[warn] _default_ VirtualHost overlap on port 80, the first has precedence

    http://blog.csdn.net/kaizhu_qin/article/details/17506293 很多第一次配置apache的虚拟主机的时候,以为配置第一个虚拟主机完成以后,以后就不会 ...

  2. DOM的方法和属性

    HTML DOM 方法是我们可以在节点(HTML 元素)上执行的动作. HTML DOM 属性是我们可以在节点(HTML 元素)设置和修改的值. 编程接口 可通过 JavaScript (以及其他编程 ...

  3. think PHP5中,模板、控制器、JavaScript的url跳转重定向方法

    php控制器中的跳转: 1, header()函数是PHP中进行页面跳转的一种十分简单的方法.主要功能是将HTTP协议标头(header)输出到浏览器. header("Location: ...

  4. 【网易官方】极客战记(codecombat)攻略-地牢-攻破突袭

    关卡连接: https://codecombat.163.com/play/level/hack-and-dash 通过加速药来逃离地牢精灵 简介: 空气中弥漫着危险的气息.你应该从地牢里逃出来. 但 ...

  5. QT+VS后中文字符乱码问题

    在VS中写QT项目会出现中文乱码现象,尤其是控件的中文乱码以及qDebug()时候中文乱码通用的解决办法: 在头文件(.h)前面加上如下代码: #ifdef WIN32 #pragma executi ...

  6. python 鸢尾花数据集报表展示

    import seaborn as snsimport pandas as pdimport matplotlib.pyplot as pltsns.set_style('white',{'font. ...

  7. 吴裕雄 python 机器学习——核化PCAKernelPCA模型

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...

  8. Go_runtime包

    package main import ( "fmt" "runtime" "time" ) //写在init函数里,main函数运行之前就 ...

  9. blog主题——田野(1)

    贮存一下,blog代码 QAQ 页首html <link rel='stylesheet' href='https://blog-static.cnblogs.com/files/elkyo/c ...

  10. 论STA | 工艺、工具、分析的本与末

    人类从漫长的蒙昧中觉醒之后,不再依靠着奇装异服的巫师通灵来指导生活,巫师进化成了科学家,他们试图对周遭的一切进行概括.分类.抽象,于是有了化学.物理.数学等基科.比如一粒沙,它的化学组成是什么,物理特 ...