4 releases (stable)
2.0.1 | Aug 10, 2024 |
---|---|
2.0.0 | Feb 28, 2024 |
1.0.0 | Dec 5, 2023 |
0.1.0 | Nov 18, 2023 |
#398 in Network programming
25KB
171 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
orindex.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 0.0.0.0:1965 --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_PATH |
Always |
URL_INPUT |
Sometimes |
PEER_IP |
Always |
PEER_CERT |
Sometimes |
PEER_NAME |
Sometimes |
PEER_FINGERPRINT |
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
echo "## Url"
echo "$URL"
echo
echo "### Path"
echo "$URL_PATH"
echo
echo "### Input"
echo "${URL_INPUT:-[no input]}"
echo
echo "## Certificate"
echo "${PEER_CERT:-[no certificate]}"
echo
echo "### Name"
echo "${DOVE_NAME:-[no name]}"
Dependencies
~10–21MB
~289K SLoC