vpapakir / uptime-openshift

Port of Uptime (https://github.com/fzaninotto/uptime) to run on Openshift Online
MIT License
37 stars 13 forks source link

Unexpected response code: 502 for websocket connection #4

Closed abovethewater closed 3 years ago

abovethewater commented 10 years ago

I get the following error in the console: WebSocket connection to 'ws://xxx.rhcloud.com/socket.io/1/websocket/IuKwIESH_-nUfYJbr_dA' failed: Error during WebSocket handshake: Unexpected response code: 502

Not sure if this error actually affects anything as it is likely falling back to polling.

Should I be concerned about this error? Can websockets be enabled by using port 8000 / 8443 as per https://www.openshift.com/blogs/paas-websockets

abovethewater commented 10 years ago

Having had a little play, it is indeed due to the poor support of websockets on OpenShift.

Changing line 16 of layout.ejs to that effect works

var port = 8000;
if (location.protocol === 'https:') {
  port = 8443;
}
var socket = io.connect(location.protocol + '//' + location.hostname + ':' + port);

However, that results in a cross-domain failure, as no CORS headers on the websocket response.

Accessing the site via the same port (i.e. http://xxx.rhcloud.com:8000/ or https://xxx.rhcloud.com:8443) works fine, but is ugly as hell.

ghost commented 9 years ago

Had the same issue while testing just now, here's what I did at line 16 of layout.ejs:

var port = 8000,
    protocol = 'ws://',
    isSecure = false;
if (location.protocol === 'https:') {
   port = 8443;
   protocol = 'wss://';
   isSecure = true;
}
var socket = io.connect(protocol + 'yourappname-yourdomain.rhcloud.com:' + port, {secure: isSecure});
qalqi commented 7 years ago
socket = io.connect(HOST_REMOTE, {
    transports: ['xhr-polling']
});

I had the same issue on OpenShift. Its been resolved by defining transport types