title: socket.io getting error 404 when communicating between client and server
body: <p>I'm making a small chat application using react, node and socket.io
  I want to run the app at <a href="http://localhost:3002/chat-io/" rel="nofollow noreferrer">http://localhost:3002/chat-io/</a>, but i'm getting the following error:</p>
  
  <p><code>GET http://localhost:3002/chat-io/socket.io/?EIO=3&amp;transport=polling&amp;t=N2YJ1pG 404 (Not Found)</code></p>
  
  <p>Server:</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  
  const app = express();
  
  const server = require('http').createServer(app);
  const io = require('socket.io')(server);
  
  io.path('/chat-io/socket.io');
  const cors = require('cors');
  
  const {
    addUser,
    removeUser,
    getUser,
    getUsersInRoom,
  } = require('./users');
  
  // Cors
  app.use(cors());
  
  // Serve static assets in production
  if (process.env.NODE_ENV === 'production') {
    app.use('/chat-io/', express.static(path.join(__dirname, '/client/build')));
  }
  
  app.get('/', (req, res) =&gt; {
    res.status(200).send({ response: 'Server is up and running' });
  });
  
  io.on('connection', (socket) =&gt; {
    socket.on('join', ({ name, room }, callback) =&gt; {
      const { error, user } = addUser({ id: socket.id, name, room });
  
      if (error) return callback(error);
  
      socket.join(user.room);
      socket.emit('message', { user: 'admin', text: `${user.name}, welcome to the room ${user.room}` });
      socket.broadcast.to(user.room).emit('message', { user: 'admin', text: `${user.name} has joined` });
  
      io.to(user.room).emit('roomData', { room: user.room, users: getUsersInRoom(user.room) });
  
      return callback();
    });
  
    socket.on('sendMessage', (message, callback) =&gt; {
      const user = getUser(socket.id);
  
      io.to(user.room).emit('message', { user: user.name, text: message });
      io.to(user.room).emit('roomData', { room: user.room, users: getUsersInRoom(user.room) });
  
      return callback();
    });
  
    socket.on('disconnect', () =&gt; {
      const user = removeUser(socket.id);
  
      if (user) {
        io.to(user.room).emit('message', { user: 'admin', text: `${user.name} has left.` });
      }
    });
  });
  
  server.listen(process.env.PORT || 3002, () =&gt; {
    console.log(`Server has started on port ${process.env.PORT || 3002}`);
  });
  
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>const Chat = ({ location }) =&gt; {
    const [name, setName] = useState('');
    const [room, setRoom] = useState('');
    const [messages, setMessages] = useState([]);
    const [message, setMessage] = useState('');
    const [users, setUsers] = useState('');
  
    const ENDPOINT = 'http://localhost:3002';
  
    useEffect(() =&gt; {
      const { name, room } = queryString.parse(location.search);
      socket = io(ENDPOINT, { path: '/chat-io/socket.io' });
      setName(name);
      setRoom(room);
  
      socket.emit('join', { name, room }, (error) =&gt; {
        if (error) alert(error);
      });
    }, [ENDPOINT, location.search]);
  
    useEffect(() =&gt; {
      socket.on('message', (message) =&gt; {
        setMessages([...messages, message]);
      });
  
      socket.on('roomData', ({ users }) =&gt; {
        setUsers(users);
      });
  
      return () =&gt; {
        socket.emit('disconnect');
        socket.off();
      };
    }, [messages]);
  
    const sendMessage = (e) =&gt; {
      e.preventDefault();
      if (message) socket.emit('sendMessage', message, () =&gt; setMessage(''));
    };
  };
  
  </code></pre>
  
  <p>On the client there's also some jsx, but i don't think that's important.
  I can get the code to run just fine on <a href="http://localhost:3002" rel="nofollow noreferrer">http://localhost:3002</a> but i want to run it on  <a href="http://localhost:3002/chat-io/" rel="nofollow noreferrer">http://localhost:3002/chat-io/</a></p>
  
  <p>Does anyone know what i'm doing wrong? Thanks</p>