#static-file #gemini #cgi #file-server #script #command-line-arguments #file-content

app dovetail

Dovetail 🕊️ is a cgi and static file server for gemini

3 releases (stable)

2.0.0 Feb 28, 2024
1.0.0 Dec 5, 2023
0.1.0 Nov 18, 2023

#447 in Network programming

Download history 138/week @ 2024-02-25 33/week @ 2024-03-03 7/week @ 2024-03-10 60/week @ 2024-03-31 1/week @ 2024-04-07

61 downloads per month


175 lines

🕊️ Dovetail

Dovetail is a cgi and static file server for gemini, inspired by agate, built with 🦊 Fluffer.

🧰 Tutorial

To get started, create a content directory. This directory will mirror how your routes are laid out.

  • A CGI script must be executable, and have the .cgi file extension. This extension is ignored in the actual route.

  • You can serve a gemtext document or a CGI script at the root of a path by naming it either index.gmi or index.gmi.cgi.

  • Also, mimetypes are guessed by a file's extension. Make sure your static files have accurate extensions.

Dovetail is configured using command-line arguments, for example:

dovetail --lang en --ip --content ./content

📜 Scripts

The server will attempt to execute files with the .cgi extension, which is elided from the route. In other words, /comment should correspond to the file content_dir/comment.cgi.

Below is a table of environment variables that will be made available to your CGI scripts. Make sure your script correctly handles variables that may not exist for every request (marked with "sometimes").

Name Exists
URL Always
URL_INPUT Sometimes
PEER_IP Always
PEER_CERT Sometimes
PEER_NAME Sometimes

🐚 Shell Example

If you're writing a CGI script in a posix shell, this template will help you get started.

Remember to never trust user input too much. Writing CGI scripts in sh can be fun, but also a tad dangerous :')

#!/bin/sh -eu

# shellcheck disable=SC2034
printf '20 text/gemini\r\n'
echo "# Dovetail Script Example"
echo "## Url"
echo "$URL"
echo "### Path"
echo "$URL_PATH"
echo "### Input"
echo "${URL_INPUT:-[no input]}"
echo "## Certificate"
echo "${PEER_CERT:-[no certificate]}"
echo "### Name"
echo "${DOVE_NAME:-[no name]}"


~338K SLoC