This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-27
Channels
- # arachne (1)
- # beginners (31)
- # boot (84)
- # cider (9)
- # clara (2)
- # cljs-dev (102)
- # cljsrn (20)
- # clojure (254)
- # clojure-belgium (1)
- # clojure-dusseldorf (17)
- # clojure-greece (7)
- # clojure-italy (6)
- # clojure-russia (2)
- # clojure-spec (8)
- # clojure-uk (9)
- # clojurescript (93)
- # component (4)
- # copenhagen-clojurians (1)
- # cursive (24)
- # datomic (22)
- # editors (1)
- # emacs (8)
- # garden (2)
- # hoplon (357)
- # lein-figwheel (1)
- # leiningen (4)
- # luminus (27)
- # mount (13)
- # off-topic (7)
- # om (71)
- # onyx (35)
- # planck (3)
- # re-frame (53)
- # reagent (35)
- # ring-swagger (24)
- # specter (10)
- # sql (6)
- # untangled (47)
- # vim (157)
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.
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
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.8.0_60]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:1.8.0_60]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.8.0_60]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.8.0_60]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[na:1.8.0_60]
at org.xnio.nio.NioSocketConduit.read(NioSocketConduit.java:286) [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:153) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:131) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:57) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88) [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:559) [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.)
Stripped down version: (password, userid and error are locally defined in the repl for testing)
(try
(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".] “"
@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.
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