💾 Archived View for mediocregopher.com › posts › mediocre-caddy-plugins-gemtext.gmi captured on 2024-08-31 at 12:20:29. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-08-18)

-=-=-=-=-=-=-

Back to All Posts

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%.

Domani project

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.

Caddy project documentation

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.

mediocre-caddy-plugins

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.

Sprig functions

Caddy `templates` directive

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.

example/Caddyfile

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.

Comitium

Mediocre Feed (HTTPs version)

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