Fork me on GitHub
#xtdb
<
2023-03-05
>
ag07:03:13

Can someone please share a trivial example of using xtdb.http-server/->xtdb-handler with reitit.ring and muuntaja? I can't figure it out. Thanks

ag12:03:48

I think I figured it out. Now, it works for routes like xtdb/status, but doesn't work for xtdb/query. Its :body is of type StreamableResponse and I don't know how to deal with it.

ag12:03:00

Doing lamebrain way like this worked, but that's probably not good:

(let [{:keys [body] :as res}
          ((->xtdb-handler my-node {}) req)]
      (assoc res :body
             (slurp (io/input-stream body))))

Jacob O'Bryant19:03:37

assuming the xtdb handler comes with all the middleware it needs (except for auth), maybe better to route xtdb requests to it without going through reitit or muuntaja first? e.g. put some middleware at/near the top of your middleware stack that checks if the request starts with _xtdb and passes it to the xtdb handler if so

ag02:03:48

Yeah, that probably would be a better way. For now, I just did this: (def app (ring/ring-handler (ring/router [["/data/*" xtdb-handler]]))) (jetty/run-jetty app opts) (defn xtdb-handler [{:keys [uri] :as req}] (let [req* (assoc req :uri (str/replace uri "/data/" "/_xtdb/")) {:keys [body] :as res} ((->xtdb-handler xtdb/my-node {}) req*)] (assoc res :body (slurp (io/input-stream body)))))