Fork me on GitHub
#aleph
<
2023-07-08
>
Jan13:07:08

Hi guys, I am trying out Aleph with Reitit and Ring and I am running into a problem where my code would just hang up - don't know if this is the correct channel to ask for help, but maybe one of you guys has an idea. I have

(ns app.core
  (:require [aleph.http :as http]
            [reitit.ring :as ring]
            [ring.middleware.params :as params]
            [ring.middleware.json :refer [wrap-json-response]]
            [ring.util.response :refer [response]]))

(defn return-path-params-handler [req]
  (wrap-json-response (response (:path-params req))))

(def handler
  (params/wrap-params
   (ring/ring-handler
    (ring/router
     [["/print/:something" return-path-params-handler]])
    (ring/create-default-handler))))

(comment
  (def http-server (http/start-server #'handler {:port 8080}))
  ,)
When I do a request to I would expect the response to be
{
  "something": "some"
}
But I don't get a response, it just hangs up and also will not timeout. What am I missing here?

valerauko14:07:08

does it work if you use something trivial for the handler? does (constantly {:status 200 :body "hello world"}) work?

Jan14:07:43

Yes, that works

Jan14:07:02

This also works

(defn return-path-params-handler [req]
  (-> (response (:something (:path-params req)))
      (assoc :headers {"content-type" "text/plain"})))
Seems to be related to wrap-json-response

Jan14:07:22

Doing this also works

(defn return-path-params-handler [req]
  (-> (response (json/write-str {:something "some"}))
      (assoc :header {"content-type" "application/json"})))
I will leave it with that for now. Thank you for looking at it

valerauko15:07:15

hmm i don't know how any of those ring utils work, but i've only seen an aleph server "hang" when the handler returns nil

Jan15:07:23

Problem was that I called wrap-json-response on the response and not the handle itself

Jan15:07:28

That is wrap-json-response returns a handler and not a response

valerauko15:07:57

glad it's figured out! 🚀