I have the need to get just the list of files from the file_server’s browse directive, to be fed into a shell script, to present a dialog for the user to pick the file which would get processed elsewhere, all inside a terminal session, ie. I can’t parse a HTML file
2. Error messages and/or full log output:
N/A
3. Caddy version:
2.7
4. How I installed and ran Caddy:
Custom compile for acme_dns
a. System environment:
Linux, Devuan/Debian/Ubuntu
typically with supervisor
b. Command:
supervisorctl start caddy
c. Service/unit/compose file:
d. My complete Caddy config:
{
log {
format json
output file /var/log/caddy/apter-global.log {
}
level debug
}
}
localhost {
respond "Hello, world!"
}
localhost:2016 {
respond "Goodbye, world!"
}
aptcacher.theb.org.in {
handle_path /echo {
respond "Goodbye, world!"
}
# Set this path to your site's directory.
log {
output file /var/log/caddy/apter-access.log {
}
level debug
}
tls {
dns acmedns /etc/acmedns/clientstorage.json
propagation_timeout -1
propagation_delay 15s
}
# Enable the static file server.
handle_path /files/* {
file_server {
browse
root /files
}
}
handle_path /hv/* {
file_server {
browse /files/template.file
root /files
}
}
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}
I just realized it isn’t documented, but if you include the browse sub-directive in your config and set the header Accept: application/json in the request, Caddy will respond with a JSON array of the directory listing.
thought you’ve solved my problem, I still want to know if there are some simple examples/tutorialsto use the templates, as I see some other uses it’ll solve for me, but I need to know how to do the listings and loop/output over the entries… future needs
For that you’ll need to learn about Go templates. The documentation of the template handler covers the fields and functions available within templates as well as linking to other helpful resources. I don’t know of any tutorials personally, but you can find tons if you search on Google to evaluate per your own criteria.