Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected response code: 200 at client.cli/open-connection #1

Open
MawiraIke opened this issue Jan 18, 2020 · 2 comments
Open

Unexpected response code: 200 at client.cli/open-connection #1

MawiraIke opened this issue Jan 18, 2020 · 2 comments

Comments

@MawiraIke
Copy link

I get an unexpected response code error when I use cli/open-connection. The error is thrown in
ws/connect url {...} at

(let [...
       socket (js/WebSocket. url protocols)
       ...]

in haslett.client.

The error thrown is

client.cljs?rel=1578861696350:27 WebSocket connection to 'ws://localhost:10666/ws' failed: Error during WebSocket handshake: Unexpected response code: 302
Expected behaviour

A connection to an already running clojure-side server would go through to enable sending of messages between both sides.
The server starts successfully from the clojure side.

Actual behaviour

Error Error during WebSocket handshake: Unexpected response code: 302

I am using aerial.hanasu v0.2.3
What could the problem be or is this an issue for haslett?

@jsa-aerial
Copy link
Owner

The general answer to this is 'your endpoint isn't what you think it is'. That could mean the socket isn't what you think it is or more likely your routing isn't what you think it is.

If you are not using the defaults for some reason, you need to make your own handler and routes using hanasu-handlers:

(defn hanasu-handlers [& {:keys [uris] :or {uris ["/ws"]}}]

as shown here:

https://github.com/jsa-aerial/hanami/blob/cd7d66f80ac05d8769cbe85d91a0020bd9cb11cd/src/clj/aerial/hanami/core.clj#L192

and used here:
https://github.com/jsa-aerial/hanami/blob/cd7d66f80ac05d8769cbe85d91a0020bd9cb11cd/examples/basic_charts.clj#L31

@MawiraIke
Copy link
Author

MawiraIke commented Jan 19, 2020

Thank you for your reply and for the repo hanasu, really love its simplicity.

The project I am working on uses a custom handler and I think it should work.
The :main-handler is

(def main-ring-handler
  (-> my-routes
      (ring.middleware.defaults/wrap-defaults ring.middleware.defaults/site-defaults)
      (wrap-cljsjs)
      (wrap-gzip)))

where my-routes is a compojure's defroutes value:

(defroutes my-routes
  (GET  "/" req (response/content-type
                  {:status 200
                   :session (if (session-uid req)
                              (:session req)
                              (assoc (:session req) :uid (unique-id)))
                   :body (io/input-stream (io/resource "oz/public/index.html"))}
                  "text/html"))
    ...)

Started the server with

(srv/start-server 10666 :main-handler main-ring-handler)

Edit:
Changed the connection on Cljs to be (cli/open-connection "ws://localhost:10666/"), to match the url "/". Getting an error of status code 200

Error during WebSocket handshake: Unexpected response code: 200

@MawiraIke MawiraIke changed the title Unexpected response code: 302 at client.cli/open-connection Unexpected response code: 200 at client.cli/open-connection Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants