How I Publish taravancil.com on the Peer-to-Peer Web
Updated August 31, 2018. Originally published on January 4, 2018.
I publish this website on dat://
and https://
. As of August 31, 2018, my publishing workflow involves three tools:
- Hugo, a static site generator
- The Dat CLI, for publishing updates to the Dat network
homebase
, for syncing updates from thedat://
version of my website to thehttps://
version
1. Building my website
This website is a pretty standard static website operation. I use Hugo to generate the markup that composes its pages. I don't have much to say about Hugo other than it works for me. Jekyll seems like a decent static site generator as well.
If you're curious to learn more about how Hugo works, the source for this site is at github.com/taravancil/taravancil.com. Something worth mentioning is that I don't use Hugo's baseURL
option and I set canonifyurls = false
in my config.toml
. This makes it possible to use relative URLs, so whether someone visits the site via dat://
or https://
, internal links always follow that protocol choice. For example, an internal link to my blog looks like this:
<a href="/blog">Blog</a>
When I'm ready to publish an update, I run Hugo and it generates a new version of my website in the /public
directory.
$ hugo
2. Publishing my website with Dat
I use the Dat CLI to publish and sync updates to my website. You can install dat
with npm:
$ npm i -g dat
After generating my website with Hugo, I cd
into the /public
directory and run the dat
command:
$ cd public
$ dat .
The first time I ran the dat
command in /public
, it created a Dat Archive and minted a new URL. Each subsequent time I run dat
in /public
, it syncs the updates to the existing URL: dat://4fa30df06cbeda4ae87be8fd4334a61289be6648fb0bf7f44f6b91d2385c9328
3. HTTP mirroring
Currently dat://
is only supported in Beaker, so I need my website to work over https://
too.
Further, dat://
URLs are long and difficult to remember, so it would be nice to be able to access the dat://
version of my site at a shortname like dat://taravancil.com. Luckily, Beaker supports this! Beaker piggybacks off of DNS authentication in combination with the /.well-known
convention to enable dat://
shortnames. When you visit dat://taravancil.com in Beaker, it sends a request to https://taravancil.com/.well-known/dat and expects to find a file that looks like this:
dat://4fa30df06cbeda4ae87be8fd4334a61289be6648fb0bf7f44f6b91d2385c9328
TTL=3600
Because Beaker can trust the DNS resolution, Beaker can trust that dat://taravancil.com should point to dat://4fa30df06cbeda4ae87be8fd4334a61289be6648fb0bf7f44f6b91d2385c9328.
homebase
Paul and I built a tool called homebase
that provides HTTP mirroring, sets up TLS with Let's Encrypt, and configures dat://
shortnames.
To get started with homebase
, you'll need a server with Node.js and npm installed. Something like a Digital Ocean droplet or an EC2 instance will work. You should follow the complete homebase
instructions if you decide to use it, but here's a short list of tasks that are easy to forget:
- Configure your DNS records to have
A
record that points to your server's IP address - Make sure ports 80 (HTTP), 443 (HTTPS), and 3282 (Dat) are open on your server
- Write a configuration file at
~/.homebase.yml
. Here's mine:
dats:
- url: dat://4fa30df06cbeda4ae87be8fd4334a61289be6648fb0bf7f44f6b91d2385c9328
domains:
- taravancil.com
httpMirror: true
letsencrypt:
email: "contact@taravancil.com"
agreeTos: true
After installing and configuring homebase
and daemonizing the process (I use pm2), your server will do the following:
- Remain active in the peer-to-peer swarm for the
dat://
version of your site, so there will always be an active "seeder" hosting its files - Listen for updates to the
dat://
version of your site, and sync them to the directory that composes thehttps://
version of your site - Serve the
https://
version of your website
Summary
Here's what I do to publish an update to my website:
- Type some new words on my blog
- Run
hugo
in the top-level directory of my website's source cd
into/public
and run thedat
command
That's it! My server automatically syncs the updates using dat://
and the changes are propagated to both dat://taravancil.com and https://taravancil.com within seconds.
Let me know if you try out this workflow! I'm @taravancil on Twitter and I hang out in #beakerbrowser on freenode. I'd love to hear how it goes for you, or offer a helping hand if you run into trouble.