Static Files
In the early days of the internet, web servers were used to serve up static HTML pages and images. Although technology has progressed a great deal since then, serving up static resources is still very much a requirement of today's web servers.
Thinking back to our CSV file of tennis matches from Chapter 5, Many to One: Reducing, we may wish to make this available to download via our web service.
compojure.route
, which we previously used to provide a not-found
route, also provides a means of easily serving static files from a custom location on disk. compojure.route/files
accepts a path where the files will be exposed as well as an options map where we can override the directory that our files are served from.
The following code would allow us to access any files located under the /home/<user>/packt-http/resources/
directory by browsing to our web server's /files/<filename>
route:
(route/files "/files/" {:root "/home/<...