'Unable to connect to Socket IO on node.js but express (api works fine): Reverse Proxy implemented on IIS

This is my server.js and SocketClass. Reverse Proxy is implemented on iis to listen the port. Express api is working but the socket connection fails. on the amazon ec2 it is working fine if tested with localhost but cannot connect on the domain.

Error WebSocket connection to 'wss://url/path/?EIO=4&transport=websocket' failed:

Code


    const express = require("express"),
      session = require("express-session"),
      SocketClass = require("./libraries/socket"),
      commmonConfig = require("./config/common.config"),
      dbConfig = require("./config/db.config"),
      nocache = require("nocache"),
      cors = require("cors"),
      rateLimit = require("express-rate-limit"),
      MySQLStore = require("express-mysql-session")(session), 
      options = {
        host: dbConfig.HOST,
        port: dbConfig.PORT,
        user: dbConfig.USER,
        password: dbConfig.PASSWORD,
        database: dbConfig.DB,
      };
     
    
    
    var sessionStore = new MySQLStore(options);
    
    // Diffrent Servers
    const app = express();  
    
    // Server1
    app.set("etag", false);
    app.use(cors());
    app.use(nocache());
    app.use(express.urlencoded({ extended: true }));
    app.use(express.json());
    app.use(express.raw());
    app.use(
      session({
        key: "session_cookie_name",
        secret: commmonConfig.secret,
        resave: false,
        saveUninitialized: false,
        cookie: { maxAge: 24 * 60 * 60 },
        store: sessionStore,
      })
    );
      
    const server = app.listen(process.env.PORT || commmonConfig.serverPort, () => {
      console.log("server is lisning");
    });
    
    // Routes
     
    
    app.get("/", (req, res) => {
      res.json({ message: "API is working." });
    });
    
    app.get("/api/ping", (req, res) => {
      res.status(200).send({ status: "ok", message: "API is WOrking ...." });
    });
      
    new SocketClass(server); 
    
    
    
    //SocketClass
    class SocketClass {
      constructor(server) { 
        io({
          path: "/bridge",
          serveClient: false,
          pingInterval: 10000,
          pingTimeout: 60000,
        })
          .listen(server, {
            log: true,
          })
          //.on("connection", this.initSocket, server);
          .on("connection", (socket) => { this.initSocket(socket,(response)=>{}); }, server);
      }
    }

 


Sources

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

Source: Stack Overflow

Solution Source