Skip to content

Instantly share code, notes, and snippets.

@devn
Created January 6, 2010 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devn/270752 to your computer and use it in GitHub Desktop.
Save devn/270752 to your computer and use it in GitHub Desktop.
(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