Skip to content

Serve ANSI, ASCII & BBS art

Below is a barebones configuration using Caddy to only to serve files using the URL example.com/ansi/.

The served textfiles are located at /var/www/example.com/html.

Caddyfile
example.com {
  encode zstd gzip

  handle {
      redir /ansi /ansi/
  }

  handle_path /ansi/* {
    root * /var/www/example.com/html/ansi
    file_server
    header {
      Content-Type "text/plain; charset=iso-8859-1"
      X-Content-Type-Options nosniff
    }
  }
}

Encode
example.com {
  encode zstd gzip

The encode directive compresses the served files using the Zstandard and Gzip algorithms to reduce the file size and speed up the text file downloads.


Handle path
  handle_path /ansi/* {
    root * /var/www/example.com/html/ansi
    file_server

The handle_path directive applies the configuration to all files using the path /ansi/*.


Root
  handle_path /ansi/* {
    root * /var/www/example.com/html/ansi
    file_server

The root paired with the file_server directive sets the (virtual) root directory to /var/www/example.com/html/ansi.


Content type
    header {
      Content-Type "text/plain; charset=iso-8859-1"
      X-Content-Type-Options nosniff
    }

The header directive combined with the Content-Type "text/plain; charset=iso-8859-1" block adds a response header to tell the browser to treat the file as plain text encoded as ISO-8859-1, a legacy character set RetroTxt can understand. You cannot use CP-437 or other DOS code pages as they are not valid browser encodings.


No sniff
    header {
      Content-Type "text/plain; charset=iso-8859-1"
      X-Content-Type-Options nosniff
    }

The X-Content-Type-Options nosniff directive adds the response header to tell browsers not to sniff the content. MIME sniffing often inaccurately treats ANSI and other encoded text as binary files browsers download.