By default, file listings are disabled and a request to a directory path (where no index file is present) will result in a 404 for obscurity reasons.
This middleware may set cookies to preserve UI preferences if the user changes them.
- path is the base path to match. Any directories in this base path become browsable.
- tplfile is the location of a template file to use.
A default template will be used if no template file is specified. Without any arguments, browsing is enabled on the entire site (path=/).
Template Format
Here is a very simple example template:
… but the default template is nicer.
Notice that the name and URL are sanitized for safe rendering in a browser. Templates are presumed trusted, so if your file names are not trusted, be sure they are escaped for use in HTML documents.
You can ask for a JSON representation instead of a browse page by having application/json in your Accept header:
Examples
Allow directory listings in all folders that don’t have an index file:
Show photo album contents (in /photos) via a custom template:
Does your company use Caddy?
Purchase a commercial license to use Caddy with your business and for basic email support, along with other benefits!