(I was actually about to post this under The Gallery until I saw that this category existed)
How to make a CDN using IPFS
Note: You might not want to do this on Glitch, because, well projects sleep after 5m (without boosted) and also this could be considered abusing the platform.
Things you’ll need:
- Go-IPFS
Edit: js-ipfs can also work!npm install -g ipfs
. It does compile stuff using node-gyp tho. - 1+ computers with Go-IPFS installed.
Directions:
Setup the First Server:
- Run
ipfs daemon
to start the IPFS daemon. If you skip this step, the following directions will fail to work. - Change Directions (cd) to the folder where your file/folder is located at.
- Type the command
ipfs add [File/Folder Name]
. The response you get should look something like this.
QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG
// This is called a hash.
- Take that response (hash) and then run
ipfs pin [HASH]
. - Now that you got the file on the network, go to the other servers and run
ipfs pin [HASH]
. - Now, try the to access the file using the gateway. Open a web browser go to: https://gateway.ipfs.io/ipfs/[HASH].
Tips:
- If you want to use Cloudflare’s amazing caching, use Cloudflare’s official gateway cloudflare-ipfs.com/ipfs/[HASH] instead of gateway.ipfs.io/ipfs/[HASH]
- The more servers pinning your file, the faster it will be.
- You can use a service like Pinata instead of hosting your own server. It’s mostly free!
I’ll be making more IPFS tutorials soon! Such as replacing a hash with a domain, etc
Learn more about IPFS and how it works here!