Fork me on GitHub

Throwing another one out there. 🙂 I’m going through Web Dev with Clojure 2nd (thanks, yogthos!) adapting the picture-gallery project for my own thing.


Instead of having a login modal, I have the login screen as the home page.


On successful login, I want to load an admin dashboard.


The login form displays nicely on the home page, the creds are collected and submitted to the server, and the authentication is successful. In the handler I use (secretary/dispatch! “/dashboard”) to try to load the dashboard component.


Instead, what happens is the system re-initializes, connects to Figwheel again, and displays the login form.


This is the login handler. On the server I’ve confirmed that it’s successfully authenticating the user.

(defn login! [fields error]
   (let [{:keys [id password]} @fields]
     (reset! error nil)
     (ajax/POST "/api/login"
                {:headers        {"Authorization" (encode-auth (string/trim id) password)}
                 :handler        #(do
                                     (session/remove! :modal)
                                     (session/put! :identity id)
                                     (js/setTimeout session-timer timeout-ms)
                                     (reset! fields nil)
                                     (secretary/dispatch! "/dashboard")
                 :error-handler  #(reset! error (get-in % [:response :message]))})))


On the server, I confirm that that “/api/login” service is logging in and returning nice JSON, but the client chops it off before it can send.

"Logging in"
{:status 200, :headers {}, :body {:result :ok}, :session {:ring.middleware.anti-forgery/anti-forgery-token "OKMme0t8x3HoNk7GOzVNQEzu3vGs3pmI7p+rOPkarULwLr5CVbX9JftbOk9RtXDdI23IuqjGMtK1Jpjt", :identity "rodfrey"}}
2016-09-26 22:41:11,382 [XNIO-1 I/O-3] DEBUG  - Error reading request Connection reset by peer
	at Method) ~[na:1.8.0_60]
	at ~[na:1.8.0_60]
	at ~[na:1.8.0_60]
	at ~[na:1.8.0_60]
	at ~[na:1.8.0_60]
	at [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
	at ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
	at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest( ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent( ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent( ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
	at org.xnio.ChannelListeners.invokeChannelListener( ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
	at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady( ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
	at org.xnio.nio.NioSocketConduit.handleReady( [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
	at [xnio-nio-3.3.6.Final.jar:3.3.6.Final]


the first two lines are just printlns, with the json being the return from the handler.


if I recall correctly, dispatch! doesn’t actually change the URL, but simply runs the handler for it. You could try using (set! (.-href js/location) "#/dashboard”) instead to set the location and that should trigger the handler as well


the other thing to check is what the /dashboard route is doing to make sure it’s not causing the page to reload


Hello, I try to build a REST API which returns XML. Where could I find Info for compojure-api, how I can set the response format and output xml?


Thanks @yogthos. What I discovered is that my service is being called, but the client is aborting the connection. (Calling the service from swatter-ui with the same authoriziation works fine.)


I must be abusing the ajax call. But I don’t know how.


Stripped down version: (password, userid and error are locally defined in the repl for testing)

      (ajax/POST "/api/login"
                {:headers        {"Authorization" (encode-auth (string/trim id) password)}
                 :handler        #(prn "Success")
                 :error-handler  #(prn "Failed" %)
       (catch js/Object e
         (prn "Caught " e (.-stack e))


which gives output "Caught " #object[TypeError TypeError: Cannot call property call in object [JavaPackage com.cognitect.transit.writer]. It is not a function, it is "object".] “"


no success handler call, no error handler call


and it aborts the connection


@credulous the error sounds like there’s something in the payload that transit is chocking on


@yogthos you mean in the payload from the server? I went to the Network list in the Chrome dev tools, copied the call into curl, and executed it:


# curl '' -H 'Accept: application/transit+json' -H 'Referer: ?' -H 'Origin: ' -H 'x-csrf-token: IbuLKGpnC1Lgc6rngWlanm2iQNvlQUSHACNdtoC/7P0fdRMvySnG+SRPbINMlicPXLcKP0gn8JAysD71' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36' -H 'Authorization: Basic cm9kZnJleTp0d2VlZGxl' -H 'Content-Type: application/transit+json' --data-binary $'["~#\'",null]' --compressed
["^ ","~:result","~:ok”]


Looks like valid transit to me… not sure why the client would be choking. Maybe I have to do something special to enable transit parsing?


you’re seeing a Java exception, so I think the server is failing to parse the payload from the client


Hm, possibly.. I have prn statements at every step in the login process, including right before the return... they all print on the server console.


And there is no payload, it's just the Authorization header


noob question: got my app all build, looks great, the boss loves it, now it’s time to deploy. Is there a way to run the migratus migrations without leiningen in prod?


Ah, never fails, figured it out immediately after posting: just type DATABASE_URL=“…” java -jar myapp.jar migrate


I was typing “migratus migrate” and just getting stack dumps