I’m trying to run a file server that does the following:
It displays a directory listing for directory.
It applies directives to files contained in the directories. In my case, my files are all pre-gzipped, and need to be served accordingly (e.g., by setting `header Content-Encoding gzip
Note that matching on the “.” in a file name (the “.” that separates filename and extension) doesn’t work, since not all files I’m serving actually have an extension.
5. What I already tried:
I already tried creating a “notafile” matcher:
@notafile {
file {
not try_files {path}
}
}
Apparently, this doesn’t work as try_files also matches directories.
Btw, this is slightly incorrect. It should look like this:
@notafile {
not file {
try_files {path}
}
}
But it can also be shorted to this since v2.1:
@notafile not file {path}
Anyways, the file vs directory aspect of the file matcher is actually something I was thinking about last week when resolving a different issue - I think we could have the file matcher set a value in the replacer (i.e. set up a placeholder that can be used) to determine whether the matched file was a directory or a file. I’ll see if I can get this implemented soon. Then essentially you could do something like:
@existsOnDisk file {path}
respond "serving a {http.matchers.file.type}"
If the {path} is a directory, it would respond with serving a directory and if it’s a file, it would respond with serving a file. Something like that. And you could use the expression matcher to do something conditionally based on that, like expression {http.matchers.file.type} == 'directory'
I just updated my pending PR that fixes some behaviours with the file matcher, and added the {http.matcher.file.type} placeholder as a new feature, if you want to give it a shot: