Socket.io client connect 404 not found on Netlify

Hi,

I have a create-react-app project with socket.io. Its totally working fine in my local environment but on Netlify socket client connect is throwing 404 not found error.

Is it relating to the subdomain that given by Netlify ?

URL format : https://my-app.netlify.com

Server side

const express = require('express');
const http = require("http");
const app = express();
const server = http.createServer(app);

    var io = socketIo(server, {
      origin: '*:*',
      requestCert: true,
      rejectUnauthorized: false,
      transports: 
        ['websocket',
        'flashsocket',
        'htmlfile',
        'xhr-polling',
        'jsonp-polling',
        'polling']
    });

    io.origins('*:*')

    io.on("connection", socket => {
      console.log("New client connected");

      socket.on("incoming reset setting", (data)=>{
         socket.broadcast.emit("reset setting");
      });

      socket.on("disconnect", () => console.log("Client disconnected"));
    });

    server.listen(port, host, async err => { .....

Client Side

import io from "socket.io-client";
const socket = io();

Error message in console :
POST https://my-app.netlify.com/socket.io/?EIO=3&transport=polling&t=MlzToxw 404

Response Header:

  1. age: 1
  2. cache-control: public, max-age=0, must-revalidate
  3. content-type: text/html; charset=utf-8
  4. date: Wed, 17 Jul 2019 01:07:02 GMT
  5. etag: 1563199611-ssl
  6. server: Netlify
  7. status: 404
  8. x-nf-request-id: 7bc105e5-931c-4341-a064-4dfc2e2a1f43-29945836

Request Header :

  1. :authority: my-app.netlify.com
  2. :method: POST
  3. path: /socket.io/?EIO=3&transport=polling&t=Mlzf4Es
  4. :scheme: https
  5. accept: /
  6. accept-encoding: gzip, deflate, br
  7. accept-language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7
  8. cache-control: no-cache
  9. content-length: 3
  10. content-type: text/plain;charset=UTF-8
  11. origin: URL
  12. pragma: no-cache
  13. user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36

Hi,

Just to be clear, you are hosting a node server with socket.io and you’re trying to make a connection to it for real-time communication, primarily through websockets. I don’t see any proxy redirects setup on your current deploy so I assume you are trying to connect directly to it from your client app. This request doesn’t pass through netlify, the connection goes straight from the client browser to the backend, which means you should probably check your server logs to see what’s happening.

Can you provide more details on what’s wrong as well as a link to a page where you are seeing the error so others can check it out? Thanks.