Created
January 6, 2010 22:35
-
-
Save devn/270752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn serve-file | |
"Attempts to serve up a static file from a directory, which defaults to | |
'./public'. Nil is returned if the file does not exist. If the file is a | |
directory, the function looks for a file in the directory called 'index.*'." | |
([path] | |
(serve-file "public" path)) | |
([root path] | |
(let [filepath (File. root path)] | |
(if (safe-path? root path) | |
(cond | |
(.isFile filepath) | |
filepath | |
(.isDirectory filepath) | |
(find-index-file filepath)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment