Publishing dcorelabs.com by Cloudflare and IPFS

DCoreLabs
DCoreLabs
Published in
2 min readOct 29, 2018

In this article, we will show you how to connect DcoreLabs web page by Cloudflare and IPFS node.

Cloudflare’s read-only Distributed Web Gateway lets you access content stored on the InterPlanetary File System (IPFS) quickly and easily, without downloading any special software or giving up any storage space on your computer.

The InterPlanetary File System (IPFS) is a distributed file storage protocol that allows computers all over the world to store and serve files as part of a giant, peer-to-peer network.

Add Content to IPFS and Retrieve It

Step 1: Install IPFS and start the daemon

$ brew install ipfs
$ ipfs init
$ ipfs daemon

Step 2: Create a content that you will add to IPFS — create a new directory, go into it and copy content there.

for example:

$ cd ~/Desktop
$ mkdir dcorelabs-web
$ cp -r /source/. /dcorelabs-web/

Step 3: Add and Pin the content to IPFS

ipfs add -r dcorelabs-web
added <hash> dcorelabs-web
ipfs pin add -r /ipfs/<hash>

Our website is now available from cloudflare-ipfs.com/ipfs/<hash> That’s pretty cool. But it’s not perfect. We want it served from our own domain.

Here’s how to set that all up.

Connect website to Cloudflare Ipfs gateway

Normally, every piece of content added to IPFS is addressed by a long, complicated hash. These hashes are difficult to work with and basically impossible for any human to remember. Cloudflare’s gateway allows you to host your website on IPFS and still have it accessible from a custom domain name. This allows an end user to access our website without needing to memorize any hash or download any software.

Prerequisites:

A domain that you own.
Access to your domain’s DNS records.
All of the content for your website collected into one folder, with a file called index.html.

  1. CNAME for dcorelabs.com pointing to www.cloudflare-ipfs.com
  2. TXT record for _dnslink.dcorelabs.com with the value dnslink=/ipfs/<your_hash_here>

Now any request to dcorelabs.com will resolve to cloudflare-ipfs.com/ipfs/<your_hash_here>.

Automatic redirect based on browser language

To enable browser language redirect we have used Javascript redirection

var language = navigator.language || navigator.browserLanguage
console.log(language)
if (language.indexOf('zh') > -1) {
document.location.href = '//dcorelabs.com/cn';
}

Automatic redirect to https web page

  1. Automatic redirect by Cloudflare
    Cloudflare offers free and automatic HTTPS support for all customers with no configuration. Cloudflare will issue an SSL certificate for your site over HTTPS. From the Cloudflare dashboard Crypto app, toggle the Always HTTPS feature on.
  2. Automatic redirect by Javascript
if (location.protocol != ‘https:’)
{
location.href = ‘https:’ + window.location.href.substring(window.location.protocol.length);
}

--

--

DCoreLabs
DCoreLabs

The objective of DCoreLabs is to allocate, concentrate and to empower tech-savvy talents to emphasis the innovations within global blockchain non-profit hub