netlify: WebSocket connection failed: Connection closed before receiving a handshake response

404
August 04, 2017, at 07:01 AM

I have app on Netlify and I get some error: server don't work: 9aeacd2….js:1 WebSocket connection to 'wss://xxxxxxxxxxxxx/:5000' failed: Connection closed before receiving a handshake response. Only start site is served. Locally all works perfect and I wasn't getting any error. App builds on Netlify (gulp) and this is angular app. Help me and thanks!

My server code:

"use strict";
process.title = 'node-chat';
var webSocketsServerPort = (process.env.PORT || 5000);
var webSocketServer = require('websocket').server;
var http = require('http');
var pref = '../';
var fs = require('fs');
var index = fs.readFileSync('src/index.html');
var clients = [];
var loggedUsers = [];
var tables = [];
var err;
/**
* HTTP server
*/
var server = http.createServer(function (req, res) {
    var status;
    var type;
    var file = null;
    switch (req.url) {
    case "/":
    case "/src/index.html":
        file = index;
        status = 200;
        type = "text/html";
        break;
    default:
        status = 404;
        type = "text/plain";
}
res.writeHead(status, {'Content-Type': type});
if (file !== null) {
    res.end(file);
} else {
    res.end();
}
});
server.listen(webSocketsServerPort, function () {
    console.log((new Date()) + " Server is listening on port " + 
webSocketsServerPort);
});
/**
 * WebSocket server
 */
var wsServer = new webSocketServer({
    httpServer: server
});
wsServer.on('request', function (request) {
    console.log((new Date()) + ' Connection from origin ' + request.origin + 
'.'    );
var connection = request.accept(null, request.origin);
var index = clients.push(connection) - 1;
connection.on('message', function (message) {
    if (message.type === 'utf8') { // accept only text
      var json = JSON.parse(message.utf8Data);
      switch(json.type){
        case 1:
          break;

      }
    }
});
// user disconnected
connection.on('close', function (connection) {
    console.log("DISCONNECTED");
});
});
Rent Charter Buses Company
READ ALSO
How to send push x hours later with Node.js / Heroku / Wit.ai ChatBot on Messenger

How to send push x hours later with Node.js / Heroku / Wit.ai ChatBot on Messenger

I'm developing ChatBots on Messenger with Nodejs and Heroku + Wit

238
Using wine as interpreter with pm2

Using wine as interpreter with pm2

I'm trying to run a windows service on ubuntu using wineRunning the service directly by executing wine Service

343
I cannot deploy node.js to Heroku due to a mysterious error

I cannot deploy node.js to Heroku due to a mysterious error

I have tried everythingHere is the strange part on line 20 column 3 there is nothing wrong with it!!! I even got rid of the original line to see if the error still persist and it did

284
How to Try Catch in CodeceptJS

How to Try Catch in CodeceptJS

I'm doing this in my page object:

460