taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.73k stars 193 forks source link

Channel options are being ignored #358

Closed dchacke closed 4 years ago

dchacke commented 4 years ago

Clojure noob here, but it looks like the channel socket option :port is ignored unless a CSRF token is provided. But that's not clear from the README, where you seem to omit the CSRF token. From https://raw.githubusercontent.com/ptaoussanis/sente/7d8ca800d950026a3171bdd0e438395766b8251a/README.md:

(let [{:keys [chsk ch-recv send-fn state]} (sente/make-channel-socket! "/chsk" ; Note the same path as before {:type :auto ; e/o #{:auto :ajax :ws} })]

Note that you pass the path, but no CSRF token.

I also can't seem to set a custom :host even when I provide a CSRF token.

My code is:

(let [{:keys [chsk ch-recv send-fn state]}
      (sente/make-channel-socket-client! "/chsk" "csrf-token"
       {:type :auto
        :host "foo"
        :port "8080"})]

It connects to localhost:8080 instead of foo:8080.

Am I doing something wrong, or is this an issue with the code base?

PS when protocol "http" is provided, it throws an exception saying that "http:" (with a colon) should be provided:

Invariant violation in `taoensso.sente:1440`. Test form `([:el #{"https:" "http:"}] protocol)` failed against input val `"http"`.

Is this stuff documented somewhere?

I'm on version 1.15.0.

amireldor commented 4 years ago

Hey, I also seem not to be able to provide a custom :host. My clojure-foo is not advanced but I am trying to dig into the code, maybe I'll find an answer there and share.

raymond-w-ko commented 4 years ago

I am also trying to figure out how to use another host.

Looking at make-channel-socket-client! it seems to be using encore/get-win-loc and shadowing protocol and host if :chsk-url-fn is not provided. Given that usage is deprecated, it is not desirable to specific a custom host?

I am developing the client portion locally and would like to connect to a development server in the cloud, where DB access is faster.

raymond-w-ko commented 4 years ago

I was able to workaround this for now by using this hack:

(defn chsk-url-fn [_ _ type*]
  (cond
   (and DEBUG (= type* :ws)) "wss://example.com/api/example/dev/chsk"
   (and DEBUG (= type* :ajax)) "https://example.com/api/example/dev/chsk"
   (and DEVELOPMENT (= type* :ws)) "wss://example.com/api/example/dev/chsk"
   (and DEVELOPMENT (= type* :ajax)) "https://example.com/api/example/dev/chsk"

   :else nil))

(defn start! []
  (let [opts {:type :ws
              :chsk-url-fn chsk-url-fn}
        {:keys [chsk ch-recv send-fn state]}
        (sente/make-channel-socket! nil nil opts)]
     (comment "your code here")))
Pederaugust commented 4 years ago

I have the same issue. It seems weird that manual overrides are being ignored. I used raymond-w-ko's hack

ptaoussanis commented 4 years ago

Closing for now since this seems to be related to #353 (?), which will be addressed in a moment. Please feel free to re-open if this is unrelated.

Apologies for the delay!