clojureyada

How to serve static resources in Yada


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?


Solution

  • 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}))