candy icon indicating copy to clipboard operation
candy copied to clipboard

failed: Error during WebSocket handshake: Unexpected response code: 404

Open k0fi opened this issue 7 years ago • 1 comments

Hi, I have prosody server with nginx set up on my localhost, which run fine together with other xmpp web clients like converse.js. But I'm banging my head to make Candy chat working, as I get this error, whatever configs that choose:

WebSocket connection to 'ws://127.0.0.1:5280/http-bind' failed: Error during WebSocket handshake: Unexpected response code: 404

Here is my config index.html:

		$(document).ready(function() {
			Candy.init('ws://127.0.0.1:5280/http-bind', {
				core: {
					debug: true,
					autojoin: true
				},
				view: { assets: '../res/' }
			});

			Candy.Core.connect('localhost');
		});

And /etc/nginx/sites-available/default :


server {
        listen 80 default_server;

location / {
        root /home/me/candy;
        index index.html;

        location /http-bind/ {
                proxy_pass https://127.0.0.1:5280/http-bind/;
                proxy_buffering off;
                tcp_nodelay on;
        }
        error_page  405 =200 $uri;
}
}

And /etc/prosody/prosody.cfg.lua:

modules_enabled = {
"roster";
"saslauth";
"tls";
"dialback";
"disco";
"version";
"uptime";
"time";
"ping",
"register";
"posix";
"bosh";
};
allow_registration = true;
daemonize = true;
consider_bosh_secure = true;
cross_domain_bosh = true;
pidfile = "/var/run/prosody/prosody.pid";
c2s_require_encryption = false;
authentication = "internal_plain"
log = {
debug = "/var/log/prosody/prosody.log";
error = "/var/log/prosody/prosody.err";

{ levels = { "error" }; to = "syslog";
};
}
VirtualHost "localhost"
enabled = true
ssl = {
key = "/etc/prosody/certs/example.com.key";
certificate = "/etc/prosody/certs/example.com.crt";
}
VirtualHost "anonymous.localhost"
   authentication = "anonymous"
Component "component.localhost"
component_secret = "supersecretpw"

Component "chat.localhost" "muc"

Browser console error log:

[Init] Debugging enabled
candy.bundle.js:202 [Connection] Connecting
libs.min.js:2 WebSocket connection to 'ws://127.0.0.1:5280/http-bind' failed: Error during WebSocket handshake: Unexpected response code: 404
_connect @ libs.min.js:2
connect @ libs.min.js:1
a.connect @ libs.min.js:2
a.connect @ candy.bundle.js:320
(anonymous) @ candy.bundle.js:4197
dispatch @ jquery.min.js:5
v.handle @ jquery.min.js:5
candy.bundle.js:234 [Strophe][ERROR]: Websocket error [object Event]
k.debug.b.log @ candy.bundle.js:234
error @ libs.min.js:1
_onError @ libs.min.js:2
candy.bundle.js:202 [Connection] Failed (2)
candy.bundle.js:234 [Strophe][INFO]: _doDisconnect was called
candy.bundle.js:234 [Strophe][INFO]: WebSockets _doDisconnect was called
candy.bundle.js:202 [Connection] Disconnected
candy.bundle.js:234 [Strophe][ERROR]: User connection callback caused an exception: TypeError: Cannot read property 'indexOf' of null
k.debug.b.log @ candy.bundle.js:234
error @ libs.min.js:1
_changeConnectStatus @ libs.min.js:1
_doDisconnect @ libs.min.js:1
_disconnect @ libs.min.js:2
_onError @ libs.min.js:2
candy.bundle.js:234 [Strophe][INFO]: Websocket closed

This problems bugs me for sooo long. So appreciate your hints to resolve it.

Thanks

k0fi avatar Jan 17 '18 08:01 k0fi

I stumbled upon this issue while searching for another one that's unrelated. But while I'm here I want to comment on this.

You have enabled BOSH in your prosody and the endpoint /http-bind is correct. But BOSH is not Websocket, these are two completely different things that just have the same goal in this case. You can't connect a websocket at a BOSH endpoint.

Either you enable Websocket in your prosody which will enable the endpoint /xmpp-websocket by default, or you keep your prosody configuration as-is and configure your client to use BOSH at the /http-bind endpoint.

sleeksorrow avatar Dec 07 '18 11:12 sleeksorrow