Creating a new custom browse template

1. The problem I’m having:

I have some directories in Caddy where I make certain files available for download via the browser using the file_server feature. I need to hide a few of these directories from users’ view while still allowing file downloads via wget or curl, as I have a script that consumes some of these files.

I’ve tried using the hide feature, but it not only hides the directories but also prevents downloading via wget or curl using the absolute path (URL) of the files.

I once came across a response from mholt in a 2019 post where a user asked for help with something similar, and the suggestion was to use a custom browse template.

The link to the post is: suggested hide directive · Issue #370 · caddyserver/caddy · GitHub

I would appreciate some guidance on getting started with creating this custom browse template. I know I can copy the default template and edit it, but I’m unsure how to hide directories using a custom template.

2. Error messages and/or full log output:

There were no errors.

3. Caddy version:

v2.7.6

4. How I installed and ran Caddy:

I am running Caddy via Docker.

a. System environment:

Docker version 25.0.3, build 4debf41

b. Command:

The command is executed via docker-entrypoint.sh:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. My Caddy config:

localhost {
    root * /srv
    
    file_server {
        browse /usr/share/caddy/custom_template.html
        hide .DS_Store ._.DS_Store
    }
}

5. Links to relevant resources:

Ah, you’re looking for this:

In the meantime, a custom template could simply not list the files by using an if statement to check if the filename is NOT one you want to unlist, and if not then go ahead and render it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.