'NodeJS : Socket.IO : Websocket request is showing status as finished instead of expected 101

I have a Node JS application which implements socket.io. The application works perfectly hosted on during testing. However, when deployed to Azure Apps, it starts to misbehave. Upon analyzing the requests, I observed two differences.

  1. The websocket request is sent as ws://localhost:3000/... from localhost while when on Azure Apps it's sent as wss://azure-apps-url/...
  2. The websocket request has a HTTP status of 101 when on localhost and "(finished)" when deployed.

NOTE: My azure application has websockets enabled.

I am not able to figure out what could be the issue. Any help would be appreciated. Do let me know if application code is required to debug the issue.

Edit: Added Code upon request. Server Side Code:

var express = require('express');
var app = express();
var ExpressPeerServer = require('peer').ExpressPeerServer;
var options = {
    debug: false
}
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
server.listen(process.env.PORT || 3000);

app.use('/peerjs', ExpressPeerServer(server, options));

Client Side Code

$(document).ready(function(){
//localhost:3000 to be replaced by Azure Site URL
var socket = io.connect("localhost:3000");
var peer = new Peer({host: "localhost", port: "3000", path: "/peerjs"});

//further operations with peer and socket
}


Solution 1:[1]

Updating server.listen(process.env.PORT || 3000); to server.listen(process.env.port); seems to have resolved the issue. However, the socket connections still don't work. I am assuming the implementation of PeerJS and Socket.IO both could be causing some sort of conflict.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shubhendu madhukar