1

With Compojure I can serve static resources like so:

(defroutes routes
  (route/resources "/"))

Following the Yada docs I have this working:

(def server
  (listener
    ["/"
     [["hello" (as-resource "Hello World!")]
      ["test" (resource {:produces "text/plain"
                         :response "This is a test!"})]
      [true (as-resource nil)]]]
    {:port 3000}))

But how do I make Yada serve resources from the file system?

Jacob O'Bryant
  • 311
  • 2
  • 10

2 Answers2

3

I ended up finding the answer here: Wrapping resource handlers with bidi

(ns yada-test
  (:require [yada.yada :refer [listener as-resource]]
            [bidi.ring :refer [resources]]))

(def server
  (listener
    ["/"
     [["" (resources {:prefix "public/"})]]]
    {:port 3001}))
Jacob O'Bryant
  • 311
  • 2
  • 10
0

Try the following:

(ns yada-test
  (:require [clojure.java.io :as io]
            [yada.yada :refer [listener as-resource]]]))

(def server
  (listener
    ["/"
     [["talks" (as-resource (io/file (io/resource "docs")))]
      [true (as-resource nil)]]]
    {:port 3001}))

You need to add a resource directory to your classpath and create the docs folder in there.

Martin Harrigan
  • 1,044
  • 11
  • 28
  • This allows me to get a listing of the contents of `docs` if I do `curl localhost:3001/talks`, but it doesn't let me do e.g. `curl localhost:3001/talks/index.html` (404). Is there a way to expose everything within the `docs` directory? – Jacob O'Bryant Apr 19 '19 at 14:49