(ns my.ns(:require-macros[cljs.core.match.macros :refer (match)] ; Optional, useful[cljs.core.async.macros :as asyncm :refer (go go-loop)])(:require;;[clojure.browser.repl :as repl][cljs.core.match] ; Optional, useful[cljs.core.async :as async :refer (<! >! put! chan)][taoensso.sente :as sente :refer (cb-success?)]))(let [{:keys [chsk ch-recv send-fn state]}(sente/make-channel-socket! "/chsk" {:type :auto})](def chsk chsk)(def ch-chsk ch-recv)(def chsk-send! send-fn)(def chsk-state state))(defn one [](chsk-send! [:some/request-id {:name "Rich Hickey" :type "Awesome"}]))
(ns my.http.ns(:require [compojure.core :refer :all]...;; Sente stuff[clojure.core.match :as match :refer (match)] ; Optional, useful[clojure.core.async :as async :refer (<! <!! >! >!! put! chan go go-loop)][taoensso.sente :as sente]))(let [{:keys [ch-recv send-fn ajax-post-fn ajax-get-or-ws-handshake-fn]}(sente/make-channel-socket! {})](def ring-ajax-post ajax-post-fn)(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn)(def ch-chsk ch-recv)(def chsk-send! send-fn))...(defn create-approutes [project-config browserrepl](defroutes app-routes;; Sente stuff(GET "/chsk" req (ring-ajax-get-or-ws-handshake req)) ; tried both ring-ajax-get-or-ws-handshake and #'ring-ajax-get-or-ws-handshake(POST "/chsk" req (ring-ajax-post req)) ; same here for trying both(GET "/" [](-> (ring-resp/response (with-browser-repl "index.html" browserrepl))(ring-resp/content-type "text/html")))(route/resources "/" {:root "resources/public/"})(route/not-found "Not Found")))
(defroutes ws-routes(GET "/cmd/chsk" req (ring-ajax-get-or-ws-handshake req))(POST "/cmd/chsk" req (ring-ajax-post req)))
(defn run[& [routes]](let [site (http-handler/site (compojure/routes ws-routes routes))webserver (httpkit/run-server site {:port 3002})
{:keys [ch-recv send-fn ajax-post-fn ajax-get-or-ws-handshake-fn
connected-uids]} (sente/make-channel-socket! {})]
(def ring-ajax-post ajax-post-fn)(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel(def chsk-send! send-fn) ; ChannelSocket's send API fn(def connected-uids connected-uids) ; Watchable, read-only atom(def server webserver)(sente/start-chsk-router-loop! sente-message-router ch-chsk)webserver))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(ns bkell.core
(:require-macros[cljs.core.match.macros :refer (match)] ; Optional, useful[cljs.core.async.macros :as asyncm :refer (go go-loop)])(:require[clojure.browser.repl :as repl][cljs.core.match]
[cljs.core.async :as async :refer (<! >! put! chan)][taoensso.sente :as sente :refer (cb-success?)]))
(defn chsk-url-fn [path {:as window-location :keys [protocol host pathname]} websocket?]"ws://172.28.128.5:8090/chsk")
(let [{:keys [chsk ch-recv send-fn state]}(sente/make-channel-socket! "/chsk" {:type :auto
:chsk-url-fn chsk-url-fn})](def chsk chsk)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def chsk-state state))(defn one [](chsk-send! [:some/request-id {:name "Rich Hickey" :type "Awesome"}]))
The new docstring: https://github.com/ptaoussanis/sente/blob/65fcf8d9be14bfc69a7798b5c159780d1d2a3804/src/taoensso/sente.cljx#L787
Wrt the CSRF issue, I'll try running again without it.
Now, a port changed fixed the issue for me. But before I passed in a chsk-url-fn, I was still getting a 404, even when trying with a browser (ie, using the correct port).
That 404 went away when I included the CSRF middleware. I still had to pass in a custom chsk-url-fn, but I could use it through the browser, for example.
And I'm just grokking the false `websocket?` allowance now. Ie, an https ajax connection would give me a sente URL of "wws://172.28.128.5:8090/chsk". Is that right? What about plain http?
Wrt the CSRF issue, I'll try running again without it.Out of curiosity, sure - but if you've already gone to the effort of setting up the CSRF I'd leave it in (better to have it) :-)
Now, a port changed fixed the issue for me. But before I passed in a chsk-url-fn, I was still getting a 404, even when trying with a browser (ie, using the correct port).Not sure about that, may be that something in your setup is tripping up the default `chsk-url-fn`. Would appreciate a GitHub issue on it and I'll take a closer look - may be a bug.
That 404 went away when I included the CSRF middleware. I still had to pass in a custom chsk-url-fn, but I could use it through the browser, for example.My guess is that the 404 is going away because you're passing in a custom `chsk-url-fn`, not because of the CSRF middleware. I.e. it's a broken chsk url that's causing the 404, not anything to do with the CSRF.
cljs.user> (.-location js/window)
283%2Frobots.txt%22%7D>
And I'm just grokking the false `websocket?` allowance now. Ie, an https ajax connection would give me a sente URL of "wws://172.28.128.5:8090/chsk". Is that right? What about plain http?The `chsk-url-fn` will be called with:1. The path as given to the client-side `make-channel-socket!` fn (usu. "/chsk").2. A window location map of the current page.3. A bool indicating whether Sente is requesting a WebSocket (true) or Ajax (false) connection.From these, your fn will need to produce an URL that matches your server-side channel socket route.For WebSocket connections you'll want the URL to start with "ws://" (insecure) or "wss://" (secure).For Ajax connections you'll want the URL to start with "http://" (insecure) or "https://" (secure).I wouldn't stress too much about that though - let's start with a GitHub issue since it's quite possible I can mod the default fn to cover your use-case automatically. Ideally you shouldn't need to fiddle with any of this :-)Cheers!
Ok, new github issues is here.
Hi Timothy, I just wanted to note that you can control the port Austin uses through environment variables. I do this so I can port forward, for example.
This probably won't help you though, as httpkit and the browser repl can't run on the same port.