0
votes

I have written some Clojurescript code that requires a REST interface for its communication with the server. The backend is currently in Python and I wanted to move it over to Clojure. Now I found rook https://github.com/AvisoNovate/rook which offers a nice API for REST which I was going to use.

However I would like to use ring (which is used by rook) to also serve some static content (basically html and JS of ClojureScript) on the same http server.

My setup is very similar to the one in the Rook example right now:

https://portal.aviso.io/#/document/open-source/rook/Current/example.html

(ns org.example.server
  (:import
    [org.eclipse.jetty.server Server])
  (:require
    [ring.adapter.jetty :as jetty]
    [io.aviso.rook :as rook]
    [clojure.tools.logging :as l]))

(defn start-server
  "Starts a server on the named port, and returns a function that shuts it back down."
  [port]
  (let [handler (-> (rook/namespace-handler
                      ["counters" 'org.example.resources.counters])
                    rook/wrap-with-standard-middleware)
        ^Server server (jetty/run-jetty handler {:port port :join? false})]
    (l/infof "Listening on port %d." port)
    #(.stop server)))

(defn main
  []
  (start-server 8080))

I have no clear picture on how to get this running with the ring static resources functionalities: https://github.com/ring-clojure/ring/wiki/Static-Resources

1

1 Answers

1
votes

I'm not very familiar with rook, and after taking a quick skim of the docs and a bit of the code I don't see static resources baked into it. If this is in error, please forgive me.

It looks like rook does a lot, but in the end it's still giving you a ring handler. So you should be able take the ring handler function that it returns and combine it with any other ring handler function/middleware, such as the ones that come with Ring.