sammacbeth.eu now available over DAT
Dat is one of several exiting distributed web technologies. It’s simple to use, fast and well designed, and makes it easy to self-host content without any infrastructure. Also, in the Beaker Browser, there is a great demonstration of how Dat could be replace HTTP directly in the browser.
As this blog is just a bunch of static HTML files, that makes it a prime candidate to be hosted as a Dat archive. I decided to try out how easy it is to turn my site into a peer-to-peer site. Turn’s out it’s pretty easy:
1. Build site
As my site is generated with Jekyll, we first need to create the built html version of the site which we want to host.
bundle exec jekyll build
This generates the site into the _site
folder.
2. Create a directory for the dat archive
We want to keep the dat archive for the site separate from the git repository. This is because dat will add metadata in the .dat
folder to track the history of the archive. If we used the _site
folder directly for the archive, this would get overwritten whenever we build the site. Therefore, we will have to resort to copying the build output to the dat folder whenever we want to update the site.
mkdir -p /path/to/dats/sammacbeth.eu
cp -r /path/to/sammacbeth.github.io/_site/* /path/to/dats/sammacbeth.eu/
3. Create the dat archive
Using dat’s create
command we can create a dat.json file which can be used to give the site a name and description. This will also generate a dat://
url for us. This command will also initialise the archive with metadata in .dat
. In my case I have the following in my dat.json
:
{
"title": "sammacbeth.eu",
"description": "Sam Macbeth's Blog",
"url": "dat://d116652eca93bc6608f1c09e5fb72b3f654aa3be2a3bca09bccfbe4131ff9e23"
}
4. Now share!
Now your Dat is ready, you can share it to the p2p web:
dat share
Now your site will be available under the dat url you generated in step 3, in this case dat://d116…f9e23
5. Bridge to HTTP
If you’re already running a site for the normal web, you can now mirror your dat version to your HTTP site. One simple way to do this is to clone your dat in the public html folder on your web server:
dat clone \
dat://d116652eca93bc6608f1c09e5fb72b3f654aa3be2a3bca09bccfbe4131ff9e23 \
/path/to/public_html
After cloning, you can also run sync
to keep it up to date with changes you make on your local copy:
cd /path/to/public_html
dat sync
This will also mean that your webserver acts as another seeder for your archive, meaning you don’t have to keep seeding locally.
6. Make your P2P address discoverable
The final step improves the discoverability of your dat site, by making visits from dat-enabled browser (i.e. the Beaker Browser) aware of your dat version. An added bonus is that your dat site will then appear with your site’s hostname, rather than the full dat url. In order to do this you have to:
- Serve your HTTP site over HTTPS.
- Create a
/.well-known/dat
file which points to your dat address (as described here)
In my case, https://sammacbeth.eu/.well-known/dat
contains the following:
dat://d116652eca93bc6608f1c09e5fb72b3f654aa3be2a3bca09bccfbe4131ff9e23
TTL=3600
Note, in order that the .well-known
folder is included in your archive, you can add the --ignore-hidden=false
option to the dat share
command.
Now, when visiting your site over HTTPS, a p2p option will be available:
And we now have a nice clean dat url too:
7. Updating the site<
Now everything is set up, you can update your site by simply copying new content into your local dat archive. The webserver will automatically pull in the changes and update the site on the web. If you don’t want to bother with the webserver part, you can also use a service like Hashbase to reach the web with your dat hosted site.