Serving Gemtext Files From Caddy
I've decided that I'm going to put the domani project to the side for now. It's not worth the effort of developing a web server in rust from scratch when existing webserver projects exist which do 80% of what I need, and which I could easily contribute to or extend to obtain the trailing 20%.
The Caddy webserver is a fantastic project which fits the bill nicely. It's written in Go, a language more suited to a general-purpose webserver, and has a fairly well documented system for writing plugins. Out of the box it implements quite a few of the features I had to implement for domani from scratch, namely support for automatically retrieving TLS certificates via Let's Encrypt and a full suite of HTTP server functionality. There's also the added benefit that I'm already using Caddy in my stack anyway, so by phasing out domani in favor of Caddy plugins I actually end up reducing my number of running services.
While Caddy is an excellent HTTP server, the one thing it lacks over domani is support for the gemini protocol. With that shortcoming in mind I've begun work on a repository of Caddy plugins which will, initially at least, focus on bridging that gap.
The first plugin I've developed is an extension to Caddy's template functionality. Caddy has builtin support for go text templates, and provides a lot of useful features out of the box like the Sprig functions and a markdown renderer. It's powerful enough to allow Caddy to dynamically render a directory of markdown files into an HTML website without any other dependencies.
What the `templates` directive lacks is the ability to render gemtext files to HTML. This seemed like a simple place to start, as it wouldn't require introducing an entirely new protocol to Caddy while still being something I could make use of immediately. And, in fact, it was a fairly simple place to start! You can see a usage example in the `mediocre-caddy-plugins` repo.
And you can see usage in the wild at my brand new HTTPs-based Mediocre Feed page, where I'm hosting my comitium feed. Comitium is a feed aggregator which I've discussed previously; it's an incredibly simple little tool which reads a configured set of RSS/Atom/gemlog feeds and creates a gemtext file aggregating links to all posts. My aggregated feed was previously only available over gemini, but with this new template function I was able to expose it over HTTPs as well.
The next plugin I work on will probably be a reverse proxy function which will allow Caddy to call back to a gemini server to serve a request. Combined with the `gemtext` template function this _should_ allow for serving any existing gemini site over HTTP.
-----
Published 2024-07-05
This site is a mirror of my gemini capsule. The equivalent gemini page can be found here, and you can learn more about gemini at my 🚀 What is Gemini? page.
Hi! I'm available for remote contract work. You can learn more about me and my skillset by browsing around this site, head over to my resume to find my actual work history, and shoot me an email when you're ready to get in touch.