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-webipfs 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 calledindex.html
.
- CNAME for
dcorelabs.com
pointing towww.cloudflare-ipfs.com
- TXT record for
_dnslink.dcorelabs.com
with the valuednslink=/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
- 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. - Automatic redirect by Javascript
if (location.protocol != ‘https:’)
{
location.href = ‘https:’ + window.location.href.substring(window.location.protocol.length);
}