title: Heroku app w/ socket.io refuses connection or sends 404
body: <p>After days of trying to figure out what's wrong, I came here to seek help.
  My Heroku app is using React as frontend and Socket.io as backend. Here's the drill:
  Heroku runs dyno with command "npm run start", which is set to <code>concurrently 'npm run react' 'npm run server'</code> to run both front and back ends.</p>
  
  <p>But even if I make it work (can't really even explain how), it only works on my computer. If I try going to the same page on my phone, no requests are made and I can't even tell why, since there is no debug log.</p>
  
  <p>Here is my /src/server/index.js file:</p>
  
  <pre><code>const express = require("express");
  const app = express();
  const server = require("http").Server(app);
  const io = module.exports.io = require('socket.io')(server)
  
  const port = process.env.PORT || 80
  
  const socketManager = require('./SocketManager') // All functions there
  
  io.on('connection', socketManager);
  // app.use(express.static(__dirname + '/../../build'))
  server.listen(port,() =&gt; {
      console.log("Listening on port", port)
  })
  </code></pre>
  
  <p>I use config file to dynamically change for the server url.</p>
  
  <pre><code>let server = 'https://hidden-waters-73936.herokuapp.com/socket.io/?EIO=4&amp;transport=websocket'; // 404
  
  // let server = window.location.hostname; // 404, same as above
  // let server = 'http://localhost:4001'; // works locally on heroku
  // let server = '/'; // 404, not found, AND CONNECTION_REFUSED
  // let server = 'https://127.0.0.1:4001'; // CONNECTUIN_REFUSED
  // let server = 'http://0.0.0.0:4001'; // Doesn't work at all
  
  module.exports = server;
  </code></pre>
  
  <p>Commented out lines are those that I tried. Last try was changing https to ws, as someone recommended earlier, then I tried adding <code>.com:80/socket.io...</code>, but still no luck. Every time it's a different Error</p>
  
  <p>Here's what the errors are like with uncommented server variable:
  <a href="https://imgur.com/Lf0BxV3" rel="nofollow noreferrer">https://imgur.com/Lf0BxV3</a></p>
  
  <p>I expect it to make successful requests both on my computer and phone. I'll try my laptop to see the logs and check back if I find anything useful.</p>
  
  <p>**UPDATE for @Ashish</p>
  
  <pre><code>React component
  
  import server from '../../config/serverConfig'
  const socket = socketIOClient(server);
  
  componentDidMount() {
  socket.emit("test", {});
  }
  </code></pre>
  
  <p>** EDIT:
  My Heroku logs seem to tell me something else is going on:</p>
  
  <pre><code>2019-05-13T16:59:55.472135+00:00 app[web.1]: [1] [33m[nodemon] 1.19.0[39m
  2019-05-13T16:59:55.474073+00:00 app[web.1]: [1] [33m[nodemon] to restart at any time, enter `rs`[39m
  2019-05-13T16:59:55.475362+00:00 app[web.1]: [1] [33m[nodemon] watching: *.*[39m
  2019-05-13T16:59:55.477060+00:00 app[web.1]: [1] [32m[nodemon] starting `node src/server/index.js`[39m
  2019-05-13T16:59:56.164302+00:00 app[web.1]: [1] Listening on port 40497
  2019-05-13T16:59:56.573081+00:00 heroku[web.1]: State changed from starting to up
  2019-05-13T16:59:57.538639+00:00 app[web.1]: [0] Something is already running on port 40497.
  2019-05-13T16:59:57.585807+00:00 app[web.1]: [0] npm run react exited with code 0
  2019-05-13T17:01:19.780332+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=hidden-waters-73936.herokuapp.com request_id=42a6c345-94b7-441a-afde-82c1e9c52e97 fwd="90.191.14.93" dyno=web.1 connect=1ms service=30004ms status=503 bytes=0 protocol=https
  </code></pre>